51

How can I fix the form size in a C# Windows Forms application and not to let user change its size?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
odiseh
  • 25,407
  • 33
  • 108
  • 151
  • 2
    Oh I got it By changing FormBorderStyle property of a form.... – odiseh May 26 '10 at 06:33
  • 1
    dont forget to mark answer as accepted if it works for you.... – Pranay Rana Aug 02 '12 at 12:03
  • @odiseh I stumbled upon this and I see you still didn't accept an answer. please mask an answer as accepted - I'm sure there is a working solution provided in the answers – Breeze Jul 31 '15 at 12:21

7 Answers7

84

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
19

Try to set

this.MinimumSize = new Size(140, 480);
this.MaximumSize = new Size(140, 480);
kleopatra
  • 51,061
  • 28
  • 99
  • 211
user1700116
  • 191
  • 1
  • 3
12

Minimal settings to prevent resize events

form1.FormBorderStyle = FormBorderStyle.FixedDialog;
form1.MaximizeBox = false;
Murilo Pontes
  • 161
  • 1
  • 4
10

Properties -> FormBorderStyle -> FixedSingle

if you can not find your Properties tool. Go to View -> Properties Window

user3130990
  • 101
  • 1
  • 2
4

I'm pretty sure this isn't the BEST way, but you could set the MinimumSize and MaximimSize properties to the same value. That will stop it.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Paul Michaels
  • 16,185
  • 43
  • 146
  • 269
1

After clicking on the form in the Design window, necessary changes can be made in the Properties window. To adjust the size of the form, the Width and Height fields of the Size property are changed. In order to keep the size of the form constant, the value FixedSingle is assigned to the FormBorderStyle property.

enter image description here

In addition, you should prevent the screen from enlarging by editing the window style; the MaximizeBox property must be set to false.

enter image description here

When the form is run as a result of the changes made through the properties window, it remains fixed in size.

enter image description here

Sercan
  • 4,739
  • 3
  • 17
  • 36
0

Set the Maximise property to False.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Abhishek Jaiswal
  • 1,161
  • 12
  • 6