.net Visual Studio - 隐藏窗体中的最大化按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7045969/
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-03 15:49:21  来源:igfitidea点击:

Visual Studio- Hiding the Maximize Button in a Form

.netvb.netwinformsvisual-studiovisual-studio-2010

提问by Walker

How do I remove the maximize button from a form? I've already disabled it but it still shows up, it just doesn't work. I want a form with only the close and minimize buttons. It's a Windows Form Application and I'm using Visual Studio 2010.

如何从表单中删除最大化按钮?我已经禁用了它,但它仍然出现,它只是不起作用。我想要一个只有关闭和最小化按钮的表单。这是一个 Windows 窗体应用程序,我使用的是 Visual Studio 2010。

回答by Mrchief

Hiding the maximize button is not possible without you painting your own window frame.

如果不绘制自己的窗口框架,则无法隐藏最大化按钮。

Having it disabled tells the user that he can't maximize the form which is good UX. Hiding it doesn't help because double clicking the title bar will still maximize the window (if you haven't disabled Maximize).

禁用它告诉用户他不能最大化良好的用户体验的表单。隐藏它没有帮助,因为双击标题栏仍然会使窗口最大化(如果您没有禁用最大化)。

You can set FormBorderStyleset to the FixedToolWindowor SizableToolWindow, but then the form will not be displayed in the Windows task bar or in the ALT+TABwindow.See update below.

您可以将 setFormBorderStyle设置为FixedToolWindowSizableToolWindow,但是该表单将不会显示在 Windows 任务栏或ALT+TAB窗口中。请参阅下面的更新。

You can hide the entire ControlBoxwhich will also remove Minimizeand Closeas well as the context menu.

您可以隐藏整个ControlBox,这也将删除MinimizeClose上下文菜单。

Pick your poison!

选择你的毒药!



Update (12/24/15)

更新 (12/24/15)

I decided to revisit the landscape with various options and it seems that:

我决定用各种选择重新审视风景,似乎:

  1. contrary to what documentationsays, setting FormBorderStyleto FixedToolWindow/SizableToolWindowno longer hides the app in task bar or ALT+TABwindow in Windows 7and up. ShowInTaskbarexclusively decides Show/Hide effect in this case (thanks to @pinowthebird for nudging me to take a re-look).
  2. Setting FormBorderStyleto FixedDialogalso hides the maximize/minimize buttons and shows up in task bar, although the default icon is now lost (not sure why).
  3. Setting MaximizeBox = Falsedoes NOT hide the buttons, again contrary to the documentation. It simply disables it (and maximize functionality via toolbar double click).
  4. Setting bothMaximizeBox = Falseand MinimizeBox = Falsehides them, irrespective of FormBorderStyle.
  1. 文档所说的相反,在Windows 7及更高版本中,设置FormBorderStyleFixedToolWindow/SizableToolWindow不再隐藏任务栏或ALT+TAB窗口中的应用程序。在这种情况下专门决定显示/隐藏效果(感谢@pinowthebird 鼓励我重新审视)。ShowInTaskbar
  2. 设置FormBorderStyleFixedDialog还会隐藏最大化/最小化按钮并显示在任务栏中,尽管默认图标现在丢失了(不知道为什么)。
  3. 设置MaximizeBox = False不会隐藏按钮,再次与文档相反。它只是禁用它(并通过双击工具栏最大化功能)。
  4. 设置两者MaximizeBox = FalseMinimizeBox = False隐藏它们,而不管FormBorderStyle.

Here are some screenshots:

以下是一些截图:

<code>FormBorderStyle</code>= <code>FixedToolWindow/SizableToolWindow</code><code>FormBorderStyle</code>= <code>FixedDialog</code><code>MaximizeBox = False</code>**both** <code>MaximizeBox = False</code>and <code>MinimizeBox = False</code>

<code>FormBorderStyle</code>= <code>FixedToolWindow/SizableToolWindow</code><code>FormBorderStyle</code>= <code>FixedDialog</code><code>MaximizeBox = False</code>**both** <code>MaximizeBox = False</code>and <code>MinimizeBox = False</code>

Conclusion:

结论:

Based on your requirements, you can either opt for 1, 2 or 3. Hope this helps future visitors.

根据您的要求,您可以选择 1、2 或 3。希望这对未来的访问者有所帮助。

Disclaimer:These tests were done in VS 2015, .Net 4.6 and a brand new WinForm app. The documentation says that these properties were available since .Net 1.1. However, as you can see in the screenshots - take the documentation with a grain of salt! Also the OS plays a vital role in the outcome.

免责声明:这些测试是在 VS 2015、.Net 4.6 和全新的 WinForm 应用程序中完成的。文档说这些属性从 .Net 1.1 开始可用。但是,正如您在屏幕截图中看到的那样 - 保留文档!此外,操作系统在结果中起着至关重要的作用。

回答by Kunal Rathod

it is simple :) do this

很简单:) 这样做

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Private Sub Form1_Load(sender As Object, e As EventArgs) 处理 MyBase.Load

    MaximizeBox = False

End Sub

Now, your client can't maximize your form, even if he/she double clicks the title bar of your form.

现在,您的客户无法最大化您的表单,即使他/她双击您表单的标题栏。

回答by Carmelo La Monica

You can change the properties of FormBorderStyleto FixedToolWindowsor SizableToolWindow.

您可以更改FormBorderStyletoFixedToolWindows或的属性SizableToolWindow

回答by Cooper

Just set the property "MaximiseBox" to be false in the properties window of the form. The same goes for the minimize box as well.

只需在表单的属性窗口中将属性“MaximiseBox”设置为 false。最小化框也是如此。

回答by Manish Pandey

In Visual Studio, First Select the Form, go to the properties and Click on Maximize Box , set it to False.It will hide the Maximize Button.

在 Visual Studio 中,首先选择窗体,转到属性并单击最大化框,将其设置为 False。它将隐藏最大化按钮。

回答by user11102

You could also skip using the default buttons by setting form border style to none in the properties which removes all the three buttons then add a customised button say with an icon file or background image(with close related content of your choice from icons8.com).

您还可以通过在属性中将表单边框样式设置为 none 来跳过使用默认按钮,这将删除所有三个按钮,然后添加一个带有图标文件或背景图像的自定义按钮(您可以从 icons8.com 中选择密切相关的内容) .

回答by user3748256

Private Sub Form4_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize


 If Me.WindowState = FormWindowState.Minimized Then

 Me.WindowState = FormWindowState.Normal 

 End If

 End Sub 

回答by IAbstract

If you set ControlBox to False, you will lose the Minimize, Maximize, and Close buttons in the upper right corner. The ControlBox is the object housing the Context menu in the upper left of your form.

如果将 ControlBox 设置为 False,您将丢失右上角的最小化、最大化和关闭按钮。ControlBox 是包含窗体左上角的上下文菜单的对象。

If you leave ControlBox set to True, you must set bothMaximize and Minimize to False - this hides both buttons. Without possibly p/invoking Win32, I don't believe your control gets any more granular than that.

如果将 ControlBox 设置为 True,则必须将Maximize 和 Minimize设置为 False - 这会隐藏两个按钮。没有可能 p/invoking Win32,我不相信你的控制比这更精细。

回答by user2431121

We can disable the two icon, minimizeand maximize. You will have to set the "minimize and maximize icon as falseboth. If either icon remains true, then all three icon will be display on your form window.

我们可以禁用两个图标,最小化最大化。您必须将“最小化和最大化图标都设置为false。如果任一图标保持为真,则所有三个图标都将显示在您的表单窗口中。