Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am making an application in C#, and it has a menu, having forms linked with it, i want that when we click on any menu link, its .cs form should be loaded in the same window

thanks
Posted

Bad idea. No, don't do it, you never really need it. Just think about it.

However, it's technically possible. By default, unlike all other controls Form cannot participate in child-parent relationship as a child, only as a parent. An attempt to insert a form in any other control will throw exception. If can be worked around by assigning false to the property TopLevel. And then you can use the form as a child, with all its ugliness, with all its non-client areas, if any… Form is not really designed for such things; it will violate normal UI style and cause other troubles. Never do it.

[EDIT]

You never mentioned MDI. MDI child is not a Control child. I did not even think that someone needs MDI and ignored this possibility. Yes, this is a different story, but…
Please see Solution 3.

—SA
 
Share this answer
 
v2
Comments
Mostafa Metwally 21-Feb-13 17:28pm    
:(
Sergey Alexandrovich Kryukov 21-Feb-13 17:32pm    
Huh?
Is the answer clear to you or not?
—SA
Mostafa Metwally 21-Feb-13 17:33pm    
someone said to me use Mdi
like..

form sell = new form();
form.MdiParent = this;
form.Dock = DockStyle.Fill;
form.Show();`
Sergey Alexandrovich Kryukov 21-Feb-13 17:42pm    
You did not mention MDI. I'll answer, too.
—SA
one way to achieve this my setting the main form as MDI Parent and all the other form as its child. have a look at the following articles

Tabbed MDI Child Forms[^]
Introduction to MDI Forms with C#[^]
MDI child as dialog form (MDI modal workaround)[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 21-Feb-13 17:46pm    
Sorry, I did not vote this time.
All your answer is correct, only I am sure it's not useful, just because MDI is a disaster. I tried to explain it in Solution 3.
—SA
Jibesh 21-Feb-13 17:53pm    
Hey Sergey, thanks for your link. I think tabbed window is the better choice instead of MDI in case of Windows Forms. I will remove the MDI - choice from my answer.
Mostafa Metwally 21-Feb-13 17:59pm    
yes the tabbed window is the best choice
Here is the idea: who needs MDI, ever? Why torturing yourself and scaring off your users?
Do yourself a great favor: do not use MDI at all. You can do much easier to implement design without it, with much better quality. MDI is highly discouraged even by Microsoft, in fact, Microsoft dropped it out of WPF and will hardly support it. More importantly, you will scare off all your users if you use MDI. Just don't. Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
How to Create MDI Parent Window in WPF?[^].

I can explain what to do instead. Please see my past answers:
How to Create MDI Parent Window in WPF? [Solution 2],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to set child forms maximized, last childform minimized[^].

—SA
 
Share this answer
 
Comments
Mostafa Metwally 21-Feb-13 17:47pm    
thank you Mr Sergey
Sergey Alexandrovich Kryukov 21-Feb-13 17:50pm    
My pleasure. Please use my advice, it will help you.
Cheers,
—SA
Mostafa Metwally 21-Feb-13 18:00pm    
sure i'll use it
i'll use tabbed window better
Sergey Alexandrovich Kryukov 21-Feb-13 18:21pm    
One of the best options, in fact. Very simple, yet nice enough...
—SA
Jibesh 21-Feb-13 17:53pm    
These are very informative. Thanks again. +5

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