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

发布于 2024-07-24 22:16:49 字数 183 浏览 9 评论 0原文

我正在开发一个 .NET C# 应用程序,它有一个主窗体,它是 MDI 容器。 当用户最大化 MDI 子项时,Windows 在容器窗体的标题栏正下方绘制一个控制条,该控件条具有子项的图标,右侧是系统按钮。 基本上,我需要的是隐藏此条并使用自定义控件来提供相同的功能。

有什么办法可以阻止Windows绘制这个MDI条带吗?

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.

Is there any way to prevent Windows from drawing this MDI strip?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦萦几度 2024-07-31 22:16:49

实际上,我找到了一种简单而有趣的方法,通过使用虚拟 MenuStrip 控件分配表单的 MainMenuStrip 属性(而不将其放入表单的 Controls 集合中)来从表单中删除此内容:

private void OnForm_Load(object sender, EventArgs e)
{
    this.MainMenuStrip = new MenuStrip();
}

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

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.

仅此而已 2024-07-31 22:16:49

多年前的这段对话表明没有办法做到这一点,他最终在主窗体上使用了用户控件,而不是实际使用 MDI 界面:

http://answers.google.com/answers/threadview/id/135136.html

我可以在网上找到的所有其他线程要么被放弃没有答案或死胡同。 我简直不敢相信这个功能如此麻烦而且不是原生可用的。

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:

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.

相对绾红妆 2024-07-31 22:16:49

有一种比将代码添加到每个表单的 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

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.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文