简体   繁体   English

当MDI子项最大化时,删除MDI容器窗体的默认MDI菜单

[英]Removing the default MDI menu of a MDI Container form when a MDI Child is maximized

I am working on a .NET C# application that has a main Form which is MDI container. 我正在开发一个.NET C#应用程序,它具有一个主要Form,它是MDI容器。 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. 当用户最大化MDI子项时,Windows在容器窗体的标题栏下方绘制一个控制条,该窗体具有子项的图标和右侧的系统按钮。 Basically, what I need is hide this strip and use a custom control to provide the same functionality. 基本上,我需要隐藏此条带并使用自定义控件来提供相同的功能。

Is there any way to prevent Windows from drawing this MDI strip? 有没有办法阻止Windows绘制这个MDI条带?

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. 这可以防止默认的MDI标题被绘制,因为Form将其功能委托给其默认菜单条(如果有的话)。 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. 由于MenuStrip控件不在Form的Controls集合中,因此它也不可见,因此它只是用作在孩子最大化时隐藏讨厌的MDI菜单的虚拟菜单。

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 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. 如果这么麻烦而且本身不可用,我无法相信这个功能。

There is an easier way than adding the code to the Load event for every form. 有一种比将代码添加到每个表单的Load事件更简单的方法。 Just place this code in the MdiParent form and substitute MenuStrip for the actual name you're using for your menustrip control. 只需将此代码放在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

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

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