Click here to Skip to main content
Rate this: bad
good
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
 
thanks
Posted 21-Feb-13 11:03am
Rate this: bad
good
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.
 
[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
  Permalink  
v2
Comments
Mostafa Metwally at 21-Feb-13 17:28pm
   
:(
Sergey Alexandrovich Kryukov at 21-Feb-13 17:32pm
   
Huh?
Is the answer clear to you or not?
—SA
Mostafa Metwally at 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 at 21-Feb-13 17:42pm
   
You did not mention MDI. I'll answer, too.
—SA
Rate this: bad
good
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)[^]
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 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 at 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 at 21-Feb-13 17:59pm
   
yes the tabbed window is the best choice
Rate this: bad
good
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:
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
  Permalink  
Comments
Mostafa Metwally at 21-Feb-13 17:47pm
   
thank you Mr Sergey
Sergey Alexandrovich Kryukov at 21-Feb-13 17:50pm
   
My pleasure. Please use my advice, it will help you.
Cheers,
—SA
Mostafa Metwally at 21-Feb-13 18:00pm
   
sure i'll use it
i'll use tabbed window better
Sergey Alexandrovich Kryukov at 21-Feb-13 18:21pm
   
One of the best options, in fact. Very simple, yet nice enough...
—SA
Jibesh at 21-Feb-13 17:53pm
   
These are very informative. Thanks again. +5
Sergey Alexandrovich Kryukov at 21-Feb-13 18:21pm
   
Thank you,
—SA

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 339
1 Nirav Prabtani 248
2 OriginalGriff 234
3 _Amy 165
4 Maciej Los 145
0 OriginalGriff 7,744
1 Sergey Alexandrovich Kryukov 6,956
2 Maciej Los 3,994
3 Peter Leow 3,708
4 CHill60 2,742


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2014
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