简体   繁体   English

如何从MDIchild窗体中删除控制框

[英]How to remove control box from MDIchild form

When I'm loading a child form in MDIparent the control box also appears. 当我在MDIparent加载子窗体时,控制框也会出现。 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. 如果确实要自定义mdiChild窗口标题栏的外观,则似乎需要通过处理WM_NCPAINT消息来处理子窗口非客户区域的WM_NCPAINT Also you need to handle messages like WM_SETCURSOR , WM_MOUSEMOVE , WM_NCLBUTTONDOWN , ... . 另外,您还需要处理WM_SETCURSORWM_MOUSEMOVEWM_NCLBUTTONDOWN等消息。

As a workaround you can use a panel instead of mdiParent. 解决方法是,可以使用面板而不是mdiParent。

  1. Create parent form and don't set IsMdiContainer . 创建父表单,不要设置IsMdiContainer
  2. Add a panel to your parent form and name it "ContainerPanel" and set its Dock property to fill. 将面板添加到您的父窗体并将其命名为“ ContainerPanel”,并将其Dock属性设置为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. 使用这种方法,您可以控制手工MDI窗口的各个方面。 For example you can use a Menu to show list of open windows and a toolstrip to close windows. 例如,您可以使用菜单显示打开的窗口列表,并使用工具栏关闭窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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