Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable resizing of a Windows Forms form

Tags:

c#

winforms

People also ask

How do I stop a form from resizing in VB net?

Answers. FormBorderStyle = FormBorderStyle. FixedSingle will prevent users from manually resizing the form. To prevent the form from being resized through code, handle the SizeChanged event and set the size back to the fixed size you want it to be.

How do you remove minimize and maximize button in Windows form?

To remove the minimize, maximize, and close buttons from your form, open your form in Design View. Under the View menu, select Properties. When the Properties window appears, set the "Control Box" property to "No". Now when the form is opened, the buttons will no longer appear in the top right of the form.

How do we set the size of the form?

By dragging either the right edge, bottom edge, or the corner, you can resize the form. The second way you can resize the form while the designer is open, is through the properties pane. Select the form, then find the Properties pane in Visual Studio. Scroll down to size and expand it.


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;

  1. First, select the form.
  2. Then, go to the properties menu.
  3. And change the property "FormBorderStyle" from sizable to Fixed3D or FixedSingle.

    This is where to modify the property "FormBorderStyle".


More precisely, add the code below to the private void InitializeComponent() method of the Form class:

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;

Explanation

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.

  • None
  • FixedSingle
  • Fixed3D
  • FixedDialog
  • Sizable
  • FixedToolWindow
  • SizableToolWindow

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

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;

Or, Graphically

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.

Graphical Properties window of Visual Studio IDE