Click here to Skip to main content
15,304,433 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
can i change the visible property for button from another form ??
BillWoodruff 23-Dec-14 10:22am
A key question to ask ... in this type of scenario ... is: did the Form that will change the visibility of the Button on the other Form CREATE the "other Form." The answer to that question may influence the strategy you choose to enable this interaction.

You'll probably find these Tips useful:
Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]
They are about transferring data, but you can use the same ways to change the visibility of a button.
Sergey Alexandrovich Kryukov 23-Dec-14 10:15am
I think this is not a very good, misleading set of articles; one of the reasons — discussing parent-child relationship between forms, something which is effectively disabled for form (after inheriting related properties from System.Windows.Forms.Control). In fact, no such relationships should affect collaboration between form instances.
I would not recommend using these articles.
Please see my answer.
BillWoodruff 23-Dec-14 10:19am
Sergey, I think you are confusing the use of the terms "parent," and "child" in the title of these articles with the idea of, literally, setting one Form to be the Parent of another Form. That's not what these articles are about !

In these articles, the term "Parent" is used to refer to the Form in which the other Forms ("Child Forms") are created.

fyi: I agree with you that the use of an Interface is, also, a very useful idea !

Merry Xmas, Bill :)
Sergey Alexandrovich Kryukov 23-Dec-14 11:43am
This is not me who used that terms in the article; of course I understand that those are not the terms associated with the property "Parent" and all; but isn't it more logical to tell that the confusion comes from the article, not from me? It is really confusing. Many beginners are already confused with child-parent stuff (in essential, not terminological aspects), why confusing them more? As to the articles, I insist that even the fact what is created where should be totally isolated from access to the form instance. Listing all those parts 1-3 is just pointless.
BillWoodruff 23-Dec-14 10:22am
+5 These articles are excellent, particularly for newcomers to WinForms.
Thomas Daniels 23-Dec-14 10:24am
Thank you!
This is 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:[^],[^].

BillWoodruff 23-Dec-14 10:22am
+5 Interfaces are good !
Sergey Alexandrovich Kryukov 23-Dec-14 11:43am
Thank you, Bill.
As the question turned out to be very popular, and my previous answers often were not well understood, probably were not clear enough, I decided to write a Tips/Trick article complete with detailed code samples and explanations: Many Questions Answered at Once — Collaboration between Windows Forms or WPF Windows.


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