windows 如何在标题栏上只显示最小化和关闭按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4510250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:50:35  来源:igfitidea点击:

How to display only Minimize and Close button on caption bar

c#windowswinformscontrols

提问by SharpUrBrain

I only want to display the Minimize and Close buttons on the caption bar, without the Maximize button using C#.net in WinForm Application. If I put this.MaximizeBox = false, the Maximize button is still displayed although it will be disabled. Any help will be appreciated. Please Provide me your excellent ideas

我只想在标题栏上显示最小化和关闭按钮,而没有在 WinForm 应用程序中使用 C#.net 的最大化按钮。如果我把 this.MaximizeBox = false,最大化按钮仍然会显示,尽管它会被禁用。任何帮助将不胜感激。请给我你的好主意

Thanks in Advance.

提前致谢。

回答by CodingGorilla

What you need to do is paint your own window chrome. See this SO question for how to do so:

您需要做的是绘制自己的窗口镀铬。请参阅此 SO 问题以了解如何执行此操作:

Custom titlebars/chrome in a WinForms app

WinForms 应用程序中的自定义标题栏/镶边

回答by Chris Clarke

If you don't mind losing the minimize button, you could use the forms FormBorderStyle to FixedToolWindow or SizableToolWindow. There are some side effects to this approach though (from MSDN):

如果您不介意丢失最小化按钮,您可以使用 FormBorderStyle 到 FixedToolWindow 或 SizableToolWindow 的形式。但是,这种方法有一些副作用(来自 MSDN):

FixedToolWindow: A tool window border that is not resizable. A tool window does not appear in the taskbar or in the window that appears when the user presses ALT+TAB. Although forms that specify FixedToolWindow typically are not shown in the taskbar, you must also ensure that the ShowInTaskbar property is set to false, since its default value is true.

SizableToolWindow: A resizable tool window border. A tool window does not appear in the taskbar or in the window that appears when the user presses ALT+TAB.

FixedToolWindow:不可调整大小的工具窗口边框。工具窗口不会出现在任务栏或用户按 ALT+TAB 时出现的窗口中。尽管指定 FixedToolWindow 的表单通常不会显示在任务栏中,但您还必须确保 ShowInTaskbar 属性设置为 false,因为其默认值为 true。

SizableToolWindow:可调整大小的工具窗口边框。工具窗口不会出现在任务栏或用户按 ALT+TAB 时出现的窗口中。

You could set the control box property on the form to false (but then you lose the close button as well as the minimize button).

您可以将表单上的控件框属性设置为 false(但随后您会丢失关闭按钮和最小化按钮)。

It looks like you should also be able to use the windows API (in this link the guy is hiding the close button for a wpf app, but I would think you could repurpose it) http://winsharp93.wordpress.com/2009/07/21/wpf-hide-the-window-buttons-minimize-restore-and-close-and-the-icon-of-a-window/

看起来你也应该能够使用 windows API(在这个链接中,这个人隐藏了 wpf 应用程序的关闭按钮,但我认为你可以重新调整它的用途)http://winsharp93.wordpress.com/2009/ 07/21/wpf-hide-the-window-buttons-minimize-restore-and-close-and-the-icon-of-a-window/