当 MDI 子级最大化时删除 MDI 容器窗体的默认 MDI 菜单
我正在开发一个 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实际上,我找到了一种简单而有趣的方法,通过使用虚拟 MenuStrip 控件分配表单的 MainMenuStrip 属性(而不将其放入表单的 Controls 集合中)来从表单中删除此内容:
这可以防止默认的 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):
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 界面:
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.
有一种比将代码添加到每个表单的 Load 事件更简单的方法。 只需将此代码放入 MdiParent 表单中,并将 MenuStrip 替换为您用于 menustrip 控件的实际名称即可。
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.