MDI窗体中,子窗体最大化后,如何不显示图标和最大化等按钮
即使将子窗体的MaxBox.MinBox,ControlBox,FormBorderStyle这些属性都设为False和NONE,子窗体最大化后,都会在MDI父窗体上显示图标和关闭,最小化,恢复大小等按钮。如何使它们消失?
------解决方案--------------------屏蔽相应的系统消息
1. 先定义
public const int WM_GETTEXT = 0x000D; //WM_GETTEXT Message value is 0x000D.Hide Icon of Child Form when it Maxmized
2. 重载WndProc函数
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_GETTEXT)
AdjustMenuItem();
else
base.WndProc(ref m);
}
3. 调整菜单的次序
private void AdjustMenuItem()
{
if (this.WindowState == FormWindowState.Maximized)
{
if (!(this.MdiParent.MainMenuStrip == null))
{
if (this.MdiParent.MainMenuStrip.Items.Count > (this.MdiParent as MainForm).OriginalMenuItemCount)
{
if (this.MdiParent.MainMenuStrip.Items[0].Alignment == ToolStripItemAlignment.Left)
{
if(this.MdiParent.MainMenuStrip.Items[0].Visible)
this.MdiParent.MainMenuStrip.Items[0].Visible = false;
}
}
}
}
}