Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
How to connect two forms? Suppose I have two forms - if I write form2.show then it display only form2.
But I want Form1 also attached with form2. I use form2.showdialogue but it is not working.
Posted
Updated 4-May-11 20:43pm
v2
Comments
OriginalGriff 5-May-11 3:04am    
Sorry, but that doesn't make much sense.
Please use the "Improve question" widget and try to explain your problem in better detail.
What does "connect two forms" mean? What does "Form1 also attached with form2" mean?
Sergey Alexandrovich Kryukov 5-May-11 14:26pm    
Very unclear indeed, but I got some idea, please see how I answered.
--SA
Legor 5-May-11 3:25am    
Unclear, be more precise.
Keith Barrow 5-May-11 6:48am    
No at all clear. What do you mean by "Form1 also attached with form2". What error are you getting? Can you post the code shown the form?
Sergey Alexandrovich Kryukov 5-May-11 13:14pm    
I have some idea what is should be, at least part of it -- please see my answer.
--SA

1 solution

You're very confused, so the question even does not make sense.

However, if you have more than one form in the same application, you need to link them with form ownership relationship. This helps to conveniently support some UI integrity in terms of form activation. You need to look at the property System.Windows.Forms.Form.Owner you need to set. Normally, your main form should own other forms (which is not so by default). A form should be added using System.Windows.Forms.Form.AddOwnedForm and removed using System.Windows.Forms.Form.RemoveOwnedForm; you can also use the property System.Windows.Forms.Form.OwnedForms.

Please see http://msdn.microsoft.com/en-us/library/system.windows.forms.form.aspx[^].

Also, consider setting the property System.Windows.Forms.Form.ShowInTaskbar to false for all owned forms. They will be shown on top of Z-order when a Owner form is shown, not independently. At the same time, the owned form can be sent on top and activated. The ownership only guarantees that no windows of other application will be placed between any forms of yours, which probably is what you require. If one form is send to the top of Z-order, all other related forms of your applications go on top automatically.

—SA
 
Share this answer
 
v7
Comments
Marc A. Brown 5-May-11 14:06pm    
You always provide such good answers. Nicely explained.
Sergey Alexandrovich Kryukov 5-May-11 14:19pm    
Thank you very much, Marc.
--SA
Ed Nutting 5-May-11 14:24pm    
I can only repeat what Marc has said ;P - My 5
Sergey Alexandrovich Kryukov 5-May-11 14:25pm    
Thank you so much,
--SA

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