Click here to Skip to main content
15,881,791 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have main form that contain a panel control, then I import another form in this panel.
The problem is the imported form appeared in the middle of panel control , so how can I move this form to right (begin from right) ?

What I have tried:

C#
form2 insideForm = new form2() { Dock = DockStyle.Fill, TopLevel = false , TopMost = true};
            insideForm.MaximizeBox = false;
            insideForm.MinimizeBox = false;
            this.panelControl1.Controls.Add(insideForm);
            insideForm.Show();
Posted
Updated 13-Jun-22 23:50pm
v2
Comments
Jo_vb.net 14-Jun-22 7:21am    
Try to change Dock = DockStyle.Fill
to
Dock = DockStyle.Right

But - as RickZeeland wrote - a usercontrol would be better.

1 solution

Do not use forms inside other forms or controls, instead use UserControls, see: UserControl Class (System.Windows.Forms) | Microsoft Docs[^]

Also see answers here: C# how do I load a form inside another form[^]

If you really need to put forms in forms, MDI can be used, but I would not recommend it, you will be in a lot of pain most of the time, see: Introduction to MDI Forms with C#[^]
 
Share this answer
 
v3
Comments
om_sh11 14-Jun-22 6:11am    
I have two forms form1 and form2 , when I click button in form1 , a form2 will imported to a panel in form1.
RickZeeland 14-Jun-22 7:06am    
Don't do that, even if you find (bad) examples on the internet and some "experts" say it's safe to do!
Dave Kreskowiak 14-Jun-22 7:44am    
The problem with using a form inside another form is that your Form2 will behave just like a top-level form. The user can revert it back to its original size and move it around its container, just like they can with Form1.

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