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

7

51

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

Jannette answered 26/5, 2010 at 6:26 Comment(3)
Oh I got it By changing FormBorderStyle property of a form....Jannette
dont forget to mark answer as accepted if it works for you....Spue
@Jannette 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 answersUnconquerable
S
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();
Spue answered 26/5, 2010 at 6:37 Comment(3)
I dont think this stops you from double clicking on the title bar and it full screensTripitaka
@Tripitaka I changed above things through designer, it worked.Double click didnt maximize it. I am using VS-2010Cultrate
@Tripitaka is right, double clicking on the title bar still maximizes the form. I am using VS 2022 community edition.Gassing
F
19

Try to set

this.MinimumSize = new Size(140, 480);
this.MaximumSize = new Size(140, 480);
Franklynfrankness answered 29/11, 2012 at 11:40 Comment(0)
J
12

Minimal settings to prevent resize events

form1.FormBorderStyle = FormBorderStyle.FixedDialog;
form1.MaximizeBox = false;
Johan answered 11/1, 2014 at 0:51 Comment(0)
C
10

Properties -> FormBorderStyle -> FixedSingle

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

Carping answered 23/12, 2013 at 23:14 Comment(0)
O
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.

Osculate answered 26/5, 2010 at 6:34 Comment(0)
P
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

Predilection answered 1/1, 2022 at 20:6 Comment(0)
S
0

Set the Maximise property to False.

Scourge answered 16/6, 2016 at 8:11 Comment(1)
"the maximise property"? Do you mean "the MaximizeBox property"?Hogan

© 2022 - 2024 — McMap. All rights reserved.