how to fire or raise an event
-
Hi i'm doing a user control in C#, where i have textbox controles, when ever a textbox is clicked (when the event textBox1.Click is fired) i need to FIRE the this.Load event (not to call the this.Load event handler method!!!). Because when i use this conrole in a form the event handler method will change. Thanks a lot PS: if you know how to do it on other .net languages tell me...it will be very helpful
-
Hi i'm doing a user control in C#, where i have textbox controles, when ever a textbox is clicked (when the event textBox1.Click is fired) i need to FIRE the this.Load event (not to call the this.Load event handler method!!!). Because when i use this conrole in a form the event handler method will change. Thanks a lot PS: if you know how to do it on other .net languages tell me...it will be very helpful
1. Define an event:
public event EventHandler TextBoxClick;
2. Define a method to fire the event:
protected vitual void OnTextBoxClick(object sender, EventArgs e)
{
if (TextBoxClick != null) TextBoxClick(sender, e);
}3. Fire the event from the associated event eg:
textBox1.Click += new EventHandler(Textboxclicked);
textBox2.Click += new EventHandler(Textboxclicked);
textBox3.Click += new EventHandler(Textboxclicked);
textBox4.Click += new EventHandler(Textboxclicked);...
void Textboxclicked(object sender, EventHandler e)
{
OnTextBoxClick(sender, e);
}4. Implemeted the TextBoxClick event on the form.
mControl.TextBoxClick += new EventHandler(methodtohandleevent);
There you have it! Merry Xmas :) WebBoxes - Yet another collapsable control, but it relies on a "graphics server" for dynamic pretty rounded corners, cool arrows and unlimited font support.