-2

I have a Winforms project with a form in it that is maximized (this.WindowState = System.Windows.Forms.FormWindowState.Maximized). When the user drags the form by its border to move the form around, it resizes to the size that I have set (which is not the maximum screen size since I do not know exactly to which values to set the MinimumSize property for it to be maximized on every screen).

I do not want this behaviour. I just want the form to stay maximized. I have set the FormBorderStyle to FixedDialog, so that the user can not resize the form by dragging the borders. I have tried to re-set the maximized window state in all kinds of events, but they do not seem to work.

Does anyone know how to fix this?

Marthe Veldhuis
  • 316
  • 2
  • 16
  • It's unclear what is your goal. Can you elaborate more? Do you want to prevent the user from moving the form? Do you want to prevent resizing? Do you want to set minimum size to size of desktop? – Reza Aghaei Oct 26 '16 at 09:37
  • The goal that I am trying to achieve it to stop the form from becoming not-maximized. How that is achieved -by stopping the user from moving the form, by setting a minimum size- I do not care. – Marthe Veldhuis Oct 26 '16 at 09:44
  • [How do you prevent a windows from being moved?](http://stackoverflow.com/questions/907830/how-do-you-prevent-a-windows-from-being-moved) – Reza Aghaei Oct 26 '16 at 10:24
  • 1
    A maximized form can't be resized or dragged around with the mouse, so it's unclear how this became a problem for you. Post the code that duplicates the problem for us. – LarsTech Oct 26 '16 at 19:30
  • @LarsTech That's the weird part, because that is exactly what happened. I still don't know what caused it because I changed my implementation, but I'm glad I'm done with it ;p. – Marthe Veldhuis Jan 05 '17 at 14:35

3 Answers3

0

This might do the trick for you

this.MinimumSize = this.MaximumSize;
this.SizeGripStyle = SizeGripStyle.Hide;

and you can also try to write onResize event of the form

this.WindowState = System.Windows.Forms.FormWindowState.Maximized

Change the FormBorderStyle to one of the Fixed values: FixedSingle, Fixed3D, FixedDialog or FixedToolBar

// Define the border style of the form to a dialog box.
this.FormBorderStyle = FormBorderStyle.FixedDialog;

// Set the MaximizeBox to false to remove the maximize box.
this.MaximizeBox = false;

// Set the MinimizeBox to false to remove the minimize box.
this.MinimizeBox = false;
Mohit S
  • 13,723
  • 6
  • 34
  • 69
  • The FormBorderStyle is already set to FixedDialog and I have added the 'this.MinimumSize = this.MaximumSize' - line. Unfortunately, that does not help. – Marthe Veldhuis Oct 26 '16 at 09:47
  • That does not help me since this is a question about the moving of the form causing it to resize, not about a user being able to resize it by dragging the sides of the form. – Marthe Veldhuis Oct 26 '16 at 10:23
  • `FormBorderStyle` does not contain a definition for `FixedToolBar`. – Ignatius Jul 14 '17 at 11:05
0

Have you tried

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

in combination with

this.WindowState = System.Windows.Forms.FormWindowState.Maximized

When you set this, you can't drag or resize the form.

However you will need to make your own close button or use "Alt+F4" to close the window.

Gwen Royakkers
  • 431
  • 2
  • 11
0

Try setting the size, maximumsize and minimumsize to the same value.

Aninda Sen
  • 63
  • 1
  • 7