Click here to Skip to main content
15,881,821 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi All!
i meet some problem about delegate, Please help me.
I have form main and form child. In form child have a label anh func "Settext" to change text in lable. In form main have a button, when i click button will create a new form child ( i can create n form child). And form main have textbox, I want to change the text in the textbox, then all text in child forms have changed over. Please help me. Warning use delegate. Thanks
Posted
Comments
[no name] 26-Jun-14 20:54pm    
Warning show us the effort you have made to get what appears to be your homework done.
Sergey Alexandrovich Kryukov 27-Jun-14 1:19am    
The parent-child relationship between forms is done functionally defunct, for a good reason. There are main form, other forms and owner/owner forms... So, I bet 1) one of your forms is the main one, but others are not children, 2) your question has nothing to do with this aspect at all.

And your problem is not quite clear. Help with what?

—SA

1 solution

Please see my comment to the question. The problem is not really formulated. Well, you want to do something, so what? why not doing it the way you want?

However, this could be related to the popular question about form collaboration. The most robust solution is implementation of an appropriate interface in form class and passing the interface reference instead of reference to a "whole instance" of a Form. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].

Please also see other solutions in this discussion. If the application is simple enough, the solution could be as simple as declaring of some internal property in one form and passing a reference to the instance of one form to the instance of another form. For more complex projects, such violation of strictly encapsulated style and loose coupling could add up the the accidental complexity of the code and invite mistakes, so the well-encapsulated solution would be preferable.

Please see also:
http://en.wikipedia.org/wiki/Accidental_complexity[^],
http://en.wikipedia.org/wiki/Loose_coupling[^].

—SA
 
Share this answer
 
Comments
tuanngocpt 27-Jun-14 7:43am    
I have form1 and form2. from form1 create form2. Now, i want change text form2 from form1 by delegate. Thanks

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