How do you stop forms from being movable and resizeable after you have maximized them in code.(this only happens if the maximize box is disabled)

If you maximize a form with the maximize button it does not let you move or resize the form.

Recommended Answers

All 3 Replies

How are you maximizing the form in code and how are you disabling the maximimize box? If you set the height and width to the entire screen then it is not truly maximized and it will let you move and resize the form. If you send it a maximize window message then it won't. This is how you should maximize it:

private void frmMaximize_Load(object sender, EventArgs e)
    {
      this.WindowState = FormWindowState.Maximized;
    }

You can also toggle between maximized and normal state by double clicking on the form's header and right clicking on the item in the windows task bar -- unless you have disabled those too.

How are you maximizing the form in code and how are you disabling the maximimize box? If you set the height and width to the entire screen then it is not truly maximized and it will let you move and resize the form. If you send it a maximize window message then it won't. This is how you should maximize it:

private void frmMaximize_Load(object sender, EventArgs e)
    {
      this.WindowState = FormWindowState.Maximized;
    }

You can also toggle between maximized and normal state by double clicking on the form's header and right clicking on the item in the windows task bar -- unless you have disabled those too.

this is how I maximize my form

this.WindowState = FormWindowState.Maximized;

this.WindowState = FormWindowState.Maximized;
It will still allow me to move and resize my form if the maximize box in the task bar is set to disabled.
If the maximize box in the task bar is set to enabled and I maximize my form with the code I cannot move the form.

Any ideas to why this works this way??

Setting the form's property this.MaximizeBox = false; prevents the form from being maximized as far as I can tell. Are you saying this is not so in your case?

Setting the form's property this.FormBorderStyle to one of the fixed border styles will prevent it from being sizeable (eg. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; . See FormBorderStyle...

As far as moving the form when maximized, you should not be able to do this, which also relates to your question: "Any ideas to why this works this way?" Maximized form fills the screen, though I don't know how this relates to virtual screens...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.