Form in a form behind my menu strip

962 Views Asked by At

I created a Form with menu strip. When I click on a menu item I want to open a new From in my main From. It works but a part of the form is behind the menu like this :

enter image description here

my code :

WindowDossierProtection wdPr = new WindowDossierProtection();
wdPr.TopLevel = false;
this.Controls.Add(wdPr);
wdPr.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
wdPr.Dock = DockStyle.Fill;
wdPr.Show();

Can you help me ? thanks !!

2

There are 2 best solutions below

0
On BEST ANSWER

Use BringToFront() to get your desired result:

WindowDossierProtection wdPr = new WindowDossierProtection();
wdPr.TopLevel = false;
this.Controls.Add(wdPr);
wdPr.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
wdPr.Dock = DockStyle.Fill;
wdPr.BringToFront();
wdPr.Show();
0
On

Do you use Visual Studio or something else? This can be easily done by the Document Outline. In Visual Studio go to : View / Other Windows / Document Outline

Or use the shortcut: Ctrl+W, U

Then, choose your form (in design view). In the Document Outline window you will see all your controls and the order that exist in your form. You simply have to drag your menuStrip in the end. (After your new form control) And voila. (I use VS2010)