Click here to Skip to main content
12,893,131 members (60,670 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# SQL-Server
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

Posted 21-Feb-13 11:03am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.


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.

Mostafa Metwally 21-Feb-13 17:28pm
Sergey Alexandrovich Kryukov 21-Feb-13 17:32pm
Is the answer clear to you or not?
Mostafa Metwally 21-Feb-13 17:33pm
someone said to me use Mdi

form sell = new form();
form.MdiParent = this;
form.Dock = DockStyle.Fill;
Sergey Alexandrovich Kryukov 21-Feb-13 17:42pm
You did not mention MDI. I'll answer, too.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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)[^]
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.
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
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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:[^],
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[^].

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.
Jibesh 21-Feb-13 17:53pm
These are very informative. Thanks again. +5
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...
Sergey Alexandrovich Kryukov 21-Feb-13 18:21pm
Thank you,

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100