126

How do I disable form resizing for users? Which property is used?

I tried AutoSize and AutoSizeMode.

Breeze
  • 2,010
  • 2
  • 32
  • 43
Diana
  • 1,293
  • 2
  • 8
  • 3

7 Answers7

266

Change the FormBorderStyle to one of the fixed values: FixedSingle, Fixed3D, FixedDialog or FixedToolWindow.

The FormBorderStyle property is under the Appearance category.

Or check this:

// Define the border style of the form to a dialog box.
form1.FormBorderStyle = FormBorderStyle.FixedDialog;

// Set the MaximizeBox to false to remove the maximize box.
form1.MaximizeBox = false;

// Set the MinimizeBox to false to remove the minimize box.
form1.MinimizeBox = false;

// Set the start position of the form to the center of the screen.
form1.StartPosition = FormStartPosition.CenterScreen;

// Display the form as a modal dialog box.
form1.ShowDialog();
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
51

Use the FormBorderStyle property. Make it FixedSingle:

this.FormBorderStyle = FormBorderStyle.FixedSingle;
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sangram Nandkhile
  • 17,634
  • 19
  • 82
  • 116
17

Use the FormBorderStyle property of your Form:

this.FormBorderStyle = FormBorderStyle.FixedDialog;
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Javed Akram
  • 15,024
  • 26
  • 81
  • 118
9

Change this property and try this at design time:

FormBorderStyle = FormBorderStyle.FixedDialog;

Designer view before the change:

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Amit Jesani
  • 155
  • 2
  • 9
9

I always use this:

// Lock form
this.MaximumSize = this.Size;
this.MinimumSize = this.Size;

This way you can always resize the form from Designer without changing code.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Laurcons
  • 99
  • 1
  • 1
8

Using the MaximumSize and MinimumSize properties of the form will fix the form size, and prevent the user from resizing the form, while keeping the form default FormBorderStyle.

this.MaximumSize = new Size(XX, YY);
this.MinimumSize = new Size(X, Y);
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ghasem
  • 14,455
  • 21
  • 138
  • 171
  • For no resizing, wouldn't this.MaximumSize = new Size(XX, YY); this.MinimumSize = this.MaximumSize also do the trick? – FullyHumanProgrammer Oct 13 '16 at 09:38
  • The problem with this approach is that the mouse cursor will still change to resize arrows when it's over the window border. Changing the FormBorderStyle means you get the right mouse cursor. – matthewscottgordon Jan 10 '19 at 15:33
1

I would set the maximum size, minimum size and remove the gripper icon of the window.

Set properties (MaximumSize, MinimumSize, and SizeGripStyle):

this.MaximumSize = new System.Drawing.Size(500, 550);
this.MinimumSize = new System.Drawing.Size(500, 550);
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
César León
  • 2,941
  • 1
  • 21
  • 18