vb.net 如何防止用户调整表单大小?

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

How do I prevent a form from being resized by the user?

vb.netwinforms

提问by l--''''''---------''''''''''''

I have a form that needs to be maximized in VB.net. I don't want the user to be able to change its size or move it around. How can I do this?

我有一个需要在 VB.net 中最大化的表单。我不希望用户能够改变它的大小或移动它。我怎样才能做到这一点?

回答by Jim Lahman

Set the highlighted properties. Set MaximimSize and MinimizeSize properties the same size

设置突出显示的属性。将 MaximimSize 和 MinimizeSize 属性设置为相同的大小

enter image description here

在此处输入图片说明

回答by amazedsaint

To prevent users from resizing, set the FormBoderStyle to Fixed3D or FixedDialog from properties window or from code

为防止用户调整大小,请从属性窗口或代码中将 FormBoderStyle 设置为 Fixed3D 或 FixedDialog

frmYour.BorderStyle = System.WinForms.FormBorderStyle.Fixed3D

And set the WindowState property to Maximized, set the MaximizeBox and MinimizeBox properties to false.

并将 WindowState 属性设置为 Maximized,将 MaximizeBox 和 MinimizeBox 属性设置为 false。

To prevent the user from moving around, override WndProc

为了防止用户四处走动,覆盖 WndProc

Protected Overrides Sub WndProc(ByRef m As Message)
        Const WM_NCLBUTTONDOWN As Integer = 161
        Const WM_SYSCOMMAND As Integer = 274
        Const HTCAPTION As Integer = 2
        Const SC_MOVE As Integer = 61456

        If (m.Msg = WM_SYSCOMMAND) And (m.WParam.ToInt32() = SC_MOVE) Then
            Return
        End If

        If (m.Msg = WM_NCLBUTTONDOWN) And (m.WParam.ToInt32() = HTCAPTION) Then
            Return
        End If

        MyBase.WndProc(m)
    End Sub

回答by Francis B.

//Set fixed border
yourForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D

//Set the state of your form to maximized       
yourForm.WindowState = FormWindowState.Maximized

//Disable the minimize box and the maximize box
yourForm.MinimizeBox = False
yourForm.MaximizeBox = False

回答by DCNYAM

Set the window start style as maximized. Then, hide the minimize and maximize buttons.

将窗口开始样式设置为最大化。然后,隐藏最小化和最大化按钮。

回答by Deep

Add some code to the Form Load event:

向 Form Load 事件添加一些代码:

me.maximumsize = new size(Width, Height)
me.minimumsize = me.maximumsize
me.maximizebox = false
me.minimizebox = false

Example:For a Form height and width of 50 pixels each:

示例:对于高度和宽度各为 50 像素的表单:

me.maximumsize = new size(50, 50)
me.minimumsize = me.maximumsize
me.maximizebox = false
me.minimizebox = false

Note that setting maximumsizeand minimumsizeto the same size as shown here prevents resizing the Form.

请注意,将maximumsize和设置minimumsize为与此处所示相同的大小可防止调整表单的大小。

回答by Rowland Shaw

You can remove the UI to control this with:

您可以删除 UI 来控制它:

frmYour.MinimizeBox = False
frmYour.MaximizeBox = False

回答by TheOddPerson

Set FormBorderStyle to 'FixedDialog'

将 FormBorderStyle 设置为“FixedDialog”

FixedDialog

固定对话框

回答by Evert

If you want to prevent resize by dragging sizegrips and by the maximize button and by maximize by doubleclick on the header text, than insert the following code in the load event of the form:

如果要通过拖动 sizegrips 和最大化按钮以及通过双击标题文本最大化来阻止调整大小,请在表单的加载事件中插入以下代码:

    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle ' Prevent size grips
    Me.MaximumSize = Me.Size ' Prevent maximize (also by doubleclick of header text)

Of course all choices of a formborderstyle beginning with Fixed will do.

当然,所有以 Fixed 开头的 formborderstyle 选择都可以。

回答by Brian Spencer

Set the min and max size of form to same numbers. Do not show min and max buttons.

将表单的最小和最大大小设置为相同的数字。不显示最小和最大按钮。

回答by Kevin Mendoza

Just change these settings in the Solution Explorer.

只需在解决方案资源管理器中更改这些设置。

MaximizeBox = False
MinimizeBox = False 

The other things such as ControlBox, Locked, and FormBorderStyle are extra.

ControlBox、Locked 和 FormBorderStyle 等其他东西是额外的。