I am working on a .NET C# application that has a main Form which is MDI container. When the user maximizes a MDI child, Windows draws a control strip right under the title bar of the container Form which has the Icon of the child and the system buttons on the right. Basically, what I need is hide this strip and use a custom control to provide the same functionality.
我正在开发一个.NET C#应用程序,它具有一个主要Form,它是MDI容器。当用户最大化MDI子项时,Windows在容器窗体的标题栏下绘制一个控制条,该窗体具有子项的图标和右侧的系统按钮。基本上,我需要隐藏此条带并使用自定义控件来提供相同的功能。
Is there any way to prevent Windows from drawing this MDI strip?
有没有办法阻止Windows绘制这个MDI条?
3 个解决方案
#1
Actually, I found an easy and interesting way to remove this thing from my form by assigning the MainMenuStrip property of the Form with a dummy MenuStrip control (without putting it in the Controls collection of the Form):
实际上,我通过使用虚拟MenuStrip控件(不将其放在Form的Controls集合中)分配Form的MainMenuStrip属性,找到了一种简单有趣的方法从表单中删除此内容:
private void OnForm_Load(object sender, EventArgs e)
{
this.MainMenuStrip = new MenuStrip();
}
This prevents the default MDI caption from being painted since the Form delegates its functionality to its default menu strip if any. Since the MenuStrip control is not in the Controls collection of the Form, it is also not visible and thus it just serves as a dummy menu used for hiding the nasty MDI menu when a child is maximized.
这可以防止默认的MDI标题被绘制,因为Form将其功能委托给其默认菜单条(如果有)。由于MenuStrip控件不在Form的Controls集合中,因此它也不可见,因此它只是用作在子项最大化时隐藏讨厌的MDI菜单的虚拟菜单。
#2
This conversation from years ago suggests that there's no way to do it, and he ended up with User Controls on the main form, instead of actually using an MDI interface:
几年前的这个对话表明没有办法做到这一点,他最终在主窗体上使用了用户控件,而不是实际使用MDI接口:
http://answers.google.com/answers/threadview/id/135136.html
Every other thread I can find online is either abandoned with no answers or a dead-end. I can't believe this functionality if so cumbersome and not something natively available.
我可以在网上找到的其他每一个帖子都要么被遗弃而没有答案或是死胡同。如果这么麻烦而且本身不可用,我无法相信这个功能。
#3
There is an easier way than adding the code to the Load event for every form. Just place this code in the MdiParent form and substitute MenuStrip for the actual name you're using for your menustrip control.
有一种比将代码添加到每个表单的Load事件更简单的方法。只需将此代码放在MdiParent表单中,并将MenuStrip替换为您用于menustrip控件的实际名称。
Private Sub MenuStrip_ItemAdded(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemEventArgs) Handles MenuStrip.ItemAdded
Dim s As New String(e.Item.GetType().ToString())
If s = "System.Windows.Forms.MdiControlStrip+SystemMenuItem" Then
e.Item.Visible = False
End If
End Sub
#1
Actually, I found an easy and interesting way to remove this thing from my form by assigning the MainMenuStrip property of the Form with a dummy MenuStrip control (without putting it in the Controls collection of the Form):
实际上,我通过使用虚拟MenuStrip控件(不将其放在Form的Controls集合中)分配Form的MainMenuStrip属性,找到了一种简单有趣的方法从表单中删除此内容:
private void OnForm_Load(object sender, EventArgs e)
{
this.MainMenuStrip = new MenuStrip();
}
This prevents the default MDI caption from being painted since the Form delegates its functionality to its default menu strip if any. Since the MenuStrip control is not in the Controls collection of the Form, it is also not visible and thus it just serves as a dummy menu used for hiding the nasty MDI menu when a child is maximized.
这可以防止默认的MDI标题被绘制,因为Form将其功能委托给其默认菜单条(如果有)。由于MenuStrip控件不在Form的Controls集合中,因此它也不可见,因此它只是用作在子项最大化时隐藏讨厌的MDI菜单的虚拟菜单。
#2
This conversation from years ago suggests that there's no way to do it, and he ended up with User Controls on the main form, instead of actually using an MDI interface:
几年前的这个对话表明没有办法做到这一点,他最终在主窗体上使用了用户控件,而不是实际使用MDI接口:
http://answers.google.com/answers/threadview/id/135136.html
Every other thread I can find online is either abandoned with no answers or a dead-end. I can't believe this functionality if so cumbersome and not something natively available.
我可以在网上找到的其他每一个帖子都要么被遗弃而没有答案或是死胡同。如果这么麻烦而且本身不可用,我无法相信这个功能。
#3
There is an easier way than adding the code to the Load event for every form. Just place this code in the MdiParent form and substitute MenuStrip for the actual name you're using for your menustrip control.
有一种比将代码添加到每个表单的Load事件更简单的方法。只需将此代码放在MdiParent表单中,并将MenuStrip替换为您用于menustrip控件的实际名称。
Private Sub MenuStrip_ItemAdded(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemEventArgs) Handles MenuStrip.ItemAdded
Dim s As New String(e.Item.GetType().ToString())
If s = "System.Windows.Forms.MdiControlStrip+SystemMenuItem" Then
e.Item.Visible = False
End If
End Sub