How can i fire event from UserControl to the Dialog ?
-
Hi ALL, I have some dialog that hold UserControl that i wrote. On the userControl i have some Button that when i click on him i need to Fire event to the dialog. How do i do it ? Does there is some method "FIRE_EVENT" that through the event? Thanks for any help.
-
Hi ALL, I have some dialog that hold UserControl that i wrote. On the userControl i have some Button that when i click on him i need to Fire event to the dialog. How do i do it ? Does there is some method "FIRE_EVENT" that through the event? Thanks for any help.
In the user control declare a delegate and event: public event ClickHandler Click1; public delegate void ClickHandler(EventArgs e); In the button's click event raise the event: i.e. if (null != Click1) Click1(e); In the dialog add a handler for Click1: myControl.Click1 += YourHandler
-
In the user control declare a delegate and event: public event ClickHandler Click1; public delegate void ClickHandler(EventArgs e); In the button's click event raise the event: i.e. if (null != Click1) Click1(e); In the dialog add a handler for Click1: myControl.Click1 += YourHandler
But How does the dialog know about the event ? What i need to know ( and does not understand ) is the dialog know about the existing of the click event before i create the connection between the dialog and the User Control ? Because i need to do it in late banding and i don't want to create connection between the dialog and the User Control in the design time - i want to create this connection in run time - Can i do it ?
-
But How does the dialog know about the event ? What i need to know ( and does not understand ) is the dialog know about the existing of the click event before i create the connection between the dialog and the User Control ? Because i need to do it in late banding and i don't want to create connection between the dialog and the User Control in the design time - i want to create this connection in run time - Can i do it ?
myControl.Click1 += new MyControl.ClickHandler(yourClickHandlerMethodInTheDialog); myControl here is an instance of the user control whose class name is MyControl.
Yanshof wrote:
What i need to know ( and does not understand ) is the dialog know about the existing of the click event before i create the connection between the dialog and the User Control ?
The instance myControl only exists at run time in all cases (even if you're using the VS Designer). -- modified at 8:33 Monday 30th July, 2007