How do I disable form resizing for users? [duplicate]
Asked Answered
H

7

127

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

I tried AutoSize and AutoSizeMode.

Helmholtz answered 24/3, 2011 at 8:12 Comment(0)
W
267

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();
Worthy answered 24/3, 2011 at 8:14 Comment(0)
M
51

Use the FormBorderStyle property. Make it FixedSingle:

this.FormBorderStyle = FormBorderStyle.FixedSingle;
Miceli answered 24/3, 2011 at 8:14 Comment(0)
S
17

Use the FormBorderStyle property of your Form:

this.FormBorderStyle = FormBorderStyle.FixedDialog;
Sharice answered 24/3, 2011 at 8:15 Comment(0)
S
9

Change this property and try this at design time:

FormBorderStyle = FormBorderStyle.FixedDialog;

Designer view before the change:

Enter image description here

Storekeeper answered 1/7, 2017 at 7:53 Comment(0)
R
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.

Rectocele answered 5/8, 2017 at 15:6 Comment(0)
J
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);
Jacky answered 3/10, 2015 at 8:17 Comment(2)
For no resizing, wouldn't this.MaximumSize = new Size(XX, YY); this.MinimumSize = this.MaximumSize also do the trick?Heighttopaper
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.Derose
J
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;
Jobi answered 8/11, 2016 at 20:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.