How can define custom events,properties

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2007
Posts: 1
Reputation: dhirennaik is an unknown quantity at this point 
Solved Threads: 0
dhirennaik dhirennaik is offline Offline
Newbie Poster

How can define custom events,properties

 
0
  #1
Dec 15th, 2007
dear freinds,
from right clicking on project I have add New Item as Component class and change
component to TextBox. Then from Toolbox i have add Textbox from this component
Now, when i put the textbox from component i need a keypress event as a parent
event for all the textboxes.

pls guide for the same
thank a lot to all.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 172
Reputation: Jugortha is an unknown quantity at this point 
Solved Threads: 16
Jugortha Jugortha is offline Offline
Junior Poster

Re: How can define custom events,properties

 
0
  #2
Dec 16th, 2007
I didn't understand very well your quqestion but I guess u shoud add an event to your customized component as a textbox nested in a componen u can not use directly its properties methods and events. I give this solution may be the problem will be solved
assume that I have created a new component in witch I added a textBox called textBox1
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace myTextBox
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private string Text
{
get { return textBox1.Text; }
set { textBox1.Text = value; }
}
/*I can fire the TextBox1 event from a method that I define as
* public to be visible when I use the component later in the main project*/
private void FireTheKeyPressEvent()
{
// This line fire the event from this method
textBox1.KeyPress += new KeyPressEventHandler(textBox1_KeyPress);
}


private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
// TO DO: implement the event handler method
}


}
}
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 172
Reputation: Jugortha is an unknown quantity at this point 
Solved Threads: 16
Jugortha Jugortha is offline Offline
Junior Poster

Re: How can define custom events,properties

 
0
  #3
Dec 16th, 2007
If u try the previous code The FireTheKeyPressEvent() will not appear in the method list when u instantiate a new compoment object now try to put public void FireTheKeyPressEvent() rather thant private void FireTheKeyPressEvent() u will see the method in the methods list of the object
I we summarize The KeyPress Event related to the textbox in the component will not appear within the component properties and method list except the u define it in the as a component class member and I insist that u define it as public
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC