62

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?

Anonymous Penguin
  • 2,027
  • 4
  • 34
  • 49
Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062
  • 1
    @Powerlord How do you know that it isn't some sort of movie player or game where you *want* every last pixel? – Anonymous Penguin Jul 18 '13 at 15:23
  • 1
    Microsoft provides a comprehensive example as part of its documentation for [Form.FormBorderStyle Property](http://msdn.microsoft.com/en-us/library/system.windows.forms.form.formborderstyle%28v=vs.110%29.aspx). – DavidRR Jul 10 '14 at 18:39

11 Answers11

126

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

enter image description here

Jim Lahman
  • 2,691
  • 2
  • 25
  • 21
  • 16
    Truly a picture is worth a thousand words! – Martin Nov 20 '14 at 03:51
  • 1
    Show 2016 and 2017 window please. all old are dead. –  Dec 19 '16 at 22:46
  • @YumYumYum the only way i found for doing this was to define it in the code as i was launching the form – AltF4_ Apr 27 '17 at 11:38
  • 2
    Controlbox false is not necessary Changing FormBorderStyle to FixedDialog automatically sets Minimize and Maximize box to false. Min/Max Size is irrelevant in this case aswell. – TheOddPerson Apr 07 '18 at 05:12
4

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

frmYour.BorderStyle = System.WinForms.FormBorderStyle.Fixed3D

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

To prevent the user from moving around, override 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
amazedsaint
  • 7,642
  • 7
  • 54
  • 83
  • constants for passing to windows api - each integer represents a Windows Message command and corresponding parameter – amazedsaint Jul 13 '09 at 13:27
  • This works best, it prevents the user from dragging the form to another monitor too (an issue I have, not sure if it is win 8 or multiple monitors causing this). Mucky (not answerers fault), but the answer is correct. – Ryan O'Neill Oct 11 '12 at 10:54
4
//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
Francis B.
  • 7,018
  • 2
  • 32
  • 54
2

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

DCNYAM
  • 11,966
  • 8
  • 53
  • 70
2

Set FormBorderStyle to 'FixedDialog'

FixedDialog

TheOddPerson
  • 149
  • 1
  • 7
1

You can remove the UI to control this with:

frmYour.MinimizeBox = False
frmYour.MaximizeBox = False
Rowland Shaw
  • 37,700
  • 14
  • 97
  • 166
1

Add some code to the Form Load event:

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:

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.

DavidRR
  • 18,291
  • 25
  • 109
  • 191
Deep
  • 31
  • 1
  • 5
1

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:

    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.

Evert
  • 11
  • 2
-1

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

Brian Spencer
  • 194
  • 2
  • 7
  • As @LarsTech said above you can still pull and resize the form manually in this scenario so this is not the full answer, maybe part of it but wouldnt prevent the issue as a whole – AltF4_ Apr 27 '17 at 11:41
-2

Just change these settings in the Solution Explorer.

MaximizeBox = False
MinimizeBox = False 

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

LarsTech
  • 80,625
  • 14
  • 153
  • 225
  • 3
    `The other things such as ControlBox, Locked, and FormBorderStyle are extra.` If the FormBorderStyle is not set to a Fixed or None type style, the user can resize the form. – LarsTech Apr 03 '15 at 20:20
-5

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

Set <code>lock = false</code> to <code>locked = true</code>

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.

Naqeeb
  • 49
  • 7