Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How i pass value from a form to a user control, using events/delegates ? I only know pass from user control to form... I know with property, but i want to know if it's possible using events...

Thanks.
Posted
Comments
BillWoodruff 23-Oct-13 1:19am    
Is it a requirement in this case that the UserControl define an Event ? If this only a case where you want to update something in the UserControl when something on the Form changes, that's easy, and does not require an Event (or a Delegate) defined in the UserControl.

Yes - it's exactly the same as with forms - you use properties: Transferring information between two forms, Part 1: Parent to Child[^] The parent is the form, the child if the user control.
If you want to go the other way: Transferring information between two forms, Part 2: Child to Parent[^] then you can use events!
 
Share this answer
 
You can use this CP article to get some ideas about how to do it..
Using a delegate to pass data between two forms[^]
There are plenty of articles on this topic online too... just search..
 
Share this answer
 
Comments
BillWoodruff 23-Oct-13 1:01am    
That article is not a good example of a reason to use delegates. The author states: "The advantage of using a delegate is that the form from which you want to send the data, doesn't need to know anything about the form that it's sending its data to."

In the example code it is obvious that Form1 has to not only have a valid reference to Form2, but it also relies on the fact that Form2 has a delegate defined that Form1 can assign a Method to.

There are much better ways to pass the data based on an Event.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900