37

How do I prevent resizing my application window?

How can I do that?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mark
  • 537
  • 3
  • 7
  • 13
  • 1
    possible duplicate of [How do I prevent a form from being resized by the user?](http://stackoverflow.com/questions/1119256/how-do-i-prevent-a-form-from-being-resized-by-the-user) – Ryan Gates Apr 25 '14 at 19:23
  • possible duplicate of [How can I prevent users from changing the window/form size when application is running](http://stackoverflow.com/questions/1330339/how-can-i-prevent-users-from-changing-the-window-form-size-when-application-is-r) – bluish Aug 25 '15 at 12:46

6 Answers6

47

On the main Form (or any Form that you don't want to be resizable), change the FormBorderStyle property to Fixed______ (FixedSingle, Fixed3D, FixedDialog, FixedToolWindow).

aKzenT
  • 7,775
  • 2
  • 36
  • 65
colithium
  • 10,269
  • 5
  • 42
  • 57
5

Another way is to define your form size and set the actual size as MinimumSize and MaximumSize via the properties.

This doesn't change your BorderStyle and the end user can't modify the size of the form.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Khh
  • 2,521
  • 1
  • 25
  • 42
  • 5
    Valid solution. But I don't like when Windows look resizable and I go to resize them and nothing happens. – colithium Sep 20 '10 at 11:20
4

There are a few of workarounds for this:

  1. Set maximum size property to a value you prefer. If you do not want the application window to be shrunk as well, then set a minimum size property. If you prefer the application to have the exact same size as that of design time, then set both maximum size and minimum size as size of your window. (Once you set maximum size or minimum size from the designer, you can't resize your window programmatically, unless you re-set maximum size and minimum size programmatically again)

  2. Set FormBorderStyle to FixedSingle or FixedDialog. The difference in looks wont be noticeable for untrained eyes, but one considerable difference I'd found from my experience is that, when you make it FixedSingle, you can still change the size programmatically. With FixedDialog its not possible. That's a huge advantage for FixedSingle property. (If you want to change size of your window programmatically here after going for FixedDialog, then you got to programmatically change FormBorderStyle first, which would create a slight blink effect when running the application).

So simply go for FixedSingle. And to make sense, do the following:

a. Set maximize box property to false.

b. Set SizeGripStyle to Hide. (@colithium points this)

nawfal
  • 70,104
  • 56
  • 326
  • 368
3

Try this:

Change FormBorderStyle to Fixed(Single, 3D, Dialog).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
anishMarokey
  • 11,279
  • 2
  • 34
  • 47
0

You can change the ResizeMode property of the Window object to CanMinimize or NoResize in the xaml or via the designer.

leumasme
  • 376
  • 4
  • 19
-2

There is a problem to find these properties in older versions of Visual Studio, like Visual Studio 2008 and ResizeMode does not appear here.

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
  if (e.CloseReason == CloseReason.UserClosing)
  {
    e.Cancel = true;
    this.WindowState = FormWindowState.Minimized;
  }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131