简体   繁体   中英

How to remove control box from MDIchild form

When I'm loading a child form in MDIparent the control box also appears. I want to remove the control box and the border of child form. Also I'm writing code as

private void Form_mainMenu_Load(object sender, EventArgs e)
{
     this.WindowState = FormWindowState.Maximized;
     this.ControlBox = false;
     this.FormBorderStyle = FormBorderStyle.None;
}

If you really want to customize the appearance of title bar of mdiChild Window, it seems you need handle painting of non-client areas of child window by handling WM_NCPAINT message. Also you need to handle messages like WM_SETCURSOR , WM_MOUSEMOVE , WM_NCLBUTTONDOWN , ... .

As a workaround you can use a panel instead of mdiParent.

  1. Create parent form and don't set IsMdiContainer .
  2. Add a panel to your parent form and name it "ContainerPanel" and set its Dock property to fill.
  3. Create your child form and add it to panel with none border style, no control box, fill dock style and non top level.

Here is sample code:

var f = new ChildForm();
f.TopLevel = false;
f.ControlBox = false;
f.Dock = DockStyle.Fill;
f.BorderStyle = System.Windows.Forms.BorderStyle.None;

/*I assume this code is in your ParentForm and so 'this' points to ParentForm that contains ContainerPanel*/
this.ContainerPanel.Controls.Add(f);
f.Show();

Using such method you can control every aspect of your hand made mdi window. For example you can use a Menu to show list of open windows and a toolstrip to close windows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM