Click here to Skip to main content
15,669,580 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to load a form inside another form I want it to look something like this.[^][^]

What I have tried:

I have tried just simply loading the form, loading it as a dialog, loading it using bunifu utils.
Updated 29-Dec-21 17:05pm
Maciej Los 29-Dec-21 15:08pm    
What have you tried till now? Please, improve your question and provide a code you've already written.

Instead of creating it as a form, create it as a UserControl.
Then you can display it as a form itself (just the control on it's own in a form) or as part of an existing form as a control.

See here: UserControl Class (System.Windows.Forms) | Microsoft Docs[^]
Share this answer
Maciej Los 29-Dec-21 15:17pm    
CPallini 12-Jan-22 16:04pm    
OriginalGriff is right.
If you want to use a form, you have to use a code like this:

Form1 insideForm = new Form1();
insideForm.TopLevel = false;

As you can see you have to do 4 steps:
1) create an instance of form you want to show inside another form,
2) change its TopLevel Property[^] to false
3) add that form to the controls of main form,
4) show a "inside-form"

That's all!

Good luck!
Share this answer
BillWoodruff 29-Dec-21 22:51pm    
Voted #1: Putting a Form inside another Form is always a bad idea. In this case the user asks how to load a Form.
Maciej Los 30-Dec-21 0:27am    
Bill, seems you don't read my answer carefully. I stated in my very first sentence that OG is right. The second part of my answer is for hardheaded people.
Btw: i've not found official documentation which states that using form inside a form is a bad practice. If you can share link to that i'll be glad.
BillWoodruff 30-Dec-21 6:09am    
Your solution is logically inconsistent: you say OG's is correct, and it is ... then, you show an example of inserting a Form into another Form's Controls which is not only a bad practice, but also is not relevant to the OP's question.
0x01AA 30-Dec-21 11:02am    
Sorry Sir, but I think you really need to explain what 'the bad idea' is. Even VS Ide does use that extremely extensively.
0x01AA 30-Dec-21 8:59am    
Have my tiny 5 against the monster 1
1) bunifu utils: you may want to ask your question on whatever resource this code library provides. i have no idea how whatever it does might affect your scenario.

2) your screen-shots are so dark i can't read them with my old eyes.

3) you create an instance of another Form in the code in another Form, often the "main Form" in a WinForm App.

4) you do not call the 'Load event directly: that is called automatically when you use 'Show or 'ShowDialog.

5. if you wish the new Form to always remain above the Form that created it on the screen: set the 'Owner Property of the new Form.
// inside the main form
Form2 f2;

// inside the main form's 'Load event handler
f2 = new Form2();
f2.Owner = this;
Share this answer
New up a form and use the Show() method.

The short answer in code is:

System.Windows.Forms.Form f = new System.Windows.Forms.Form();
Share this answer
Maciej Los 29-Dec-21 15:16pm    
No. It will show a form out of another form, but not inside another form

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