Reputation: 3137
How do I turn off the user's ability to resize a Windows Forms form?
I'm having it resize itself on a click.
Upvotes: 282
Views: 345558
Reputation:
There is far more efficient answer: just put the following instructions in the Form_Load
:
this.MinimumSize = new Size(Width, Height);
this.MaximumSize = this.MinimumSize;
Upvotes: 0
Reputation: 858
By default, FormBorderStyle
property has the sizable value FormBorderStyle.Sizable
assigned. Which enables form to be resized.
There are 7 kinds of FormBorderStyle
property values available to use.
Depending upon the kind of form, we can assign the appropriate value accordingly.
Assuming your form name is form1
.
Choose any one from below to make it as Fixed
FixedSingle, Fixed3D, FixedDialog makes the form non-resizeable, assigning None will also work but won't make sense without a control box in case.
Code snippets below, use any one of them
FixedSingle
form1.FormBorderStyle = FormBorderStyle.FixedSingle;
Fixed3D
form1.FormBorderStyle = FormBorderStyle.Fixed3D;
FixedDialog
form1.FormBorderStyle = FormBorderStyle.FixedDialog;
None [Optional] Note: There'd no control box
form1.FormBorderStyle = FormBorderStyle.None;
We can apply it graphically like this.
Make sure you've selected the form which you want to make it fixed size. then you'll see a property named FormBorderStyle
property there in Properties window.
Upvotes: 5
Reputation: 8945
None of these answers worked for me, perhaps because my window had a status bar. To fix I did this:
StatusStripObject.SizingGrip = False
The same works for a StatusBar object, e.g.:
StatusBarObject.SizingGrip = False
Upvotes: 0
Reputation: 121
Another way is to change properties "AutoSize" (set to True) and "AutosizeMode" (set to GrowAndShrink).
This has the effect of the form autosizing to the elements on it and never allowing the user to change its size.
Upvotes: 0
Reputation: 61842
Take a look at the FormBorderStyle property
form1.FormBorderStyle = FormBorderStyle.FixedSingle;
You may also want to remove the minimize and maximize buttons:
form1.MaximizeBox = false;
form1.MinimizeBox = false;
Upvotes: 466
Reputation: 1021
And change the property "FormBorderStyle" from sizable to Fixed3D or FixedSingle.
Upvotes: 95
Reputation: 19377
More precisely, add the code below to the private void InitializeComponent()
method of the Form class:
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
Upvotes: 20