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

时间:2021-11-29 14:01:56

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中最大化的表单。我不希望用户能够改变其大小或移动它。我怎样才能做到这一点?

10 个解决方案

#1


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

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

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

#2


//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

#3


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

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

#4


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

#5


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 maximumsize and minimumsize to the same size as shown here prevents resizing the Form.

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

#6


Set FormBorderStyle to 'FixedDialog'

将FormBorderStyle设置为'FixedDialog'

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

#7


You can remove the UI to control this with:

您可以删除用户界面来控制它:

frmYour.MinimizeBox = False
frmYour.MaximizeBox = False

#8


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

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

#9


Just change these settings in the Solution Explorer.

只需在Solution Explorer中更改这些设置即可。

MaximizeBox = False
MinimizeBox = False 

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

其他东西,如ControlBox,Locked和FormBorderStyle是额外的。

#10


There is an option in vb.net that lets you do all this.

vb.net中有一个选项可以让你完成所有这些。

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

The user wont be able to re-size the form or move it around, although there are other ways, this I think is the best.

用户将无法重新调整表单大小或移动它,虽然还有其他方法,我认为这是最好的。

#1


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

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

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

#2


//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

#3


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

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

#4


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

#5


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 maximumsize and minimumsize to the same size as shown here prevents resizing the Form.

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

#6


Set FormBorderStyle to 'FixedDialog'

将FormBorderStyle设置为'FixedDialog'

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

#7


You can remove the UI to control this with:

您可以删除用户界面来控制它:

frmYour.MinimizeBox = False
frmYour.MaximizeBox = False

#8


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

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

#9


Just change these settings in the Solution Explorer.

只需在Solution Explorer中更改这些设置即可。

MaximizeBox = False
MinimizeBox = False 

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

其他东西,如ControlBox,Locked和FormBorderStyle是额外的。

#10


There is an option in vb.net that lets you do all this.

vb.net中有一个选项可以让你完成所有这些。

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

The user wont be able to re-size the form or move it around, although there are other ways, this I think is the best.

用户将无法重新调整表单大小或移动它,虽然还有其他方法,我认为这是最好的。