How to force window to Maximize

  • Thread starter Thread starter Paul R
  • Start date Start date
P

Paul R

Hi,

I would like to force my application to maximize when it is launched. I
have tried this by setting the WindowState in the designer at runtime, and
have also tried executing

WindowState = FormWindowState.Normal

The form does open maximized but it does not correctly maximize to the
Windows taskbar...the bottom of the form is lost under the taskbar. If I
use the form control menu to set the form to normal and then back to
maximized, it correctly fits into the available desktop area, only going up
to the top of the taskbar. Any ideas why???

Also I want to stop the user setting the window state to normal - I either
want it maximized or minimized, but never normal. If the user
double-clicks the Window title it does set the window state to normal. Is
there an easy way to prevent this from happening???

Many thanks.
 
Hi Paul,

To maximize a windows form:

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

Additionally, this issue is also related to taskbar properties. You may
right click on the taskbar and select Properties, check if "Lock the
taskbar" and "Keep the taskbar on the top of other windows" are checked.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Hi thanks for getting back to me.

I have tried this, but have a problem. When I first tried it the window did
appear to be maximized as it filled the screen, but I could still pick up
the window and move it around the screen.

I played around with the form's ControlBox/MaximizeBox/MinimizeBox
properties and it seems that the window will only maximize itself correctly
if the Maximize box is set to true.

This is fine, but leads on to my next problem: I do not want the user to
have access to the maximize box on the form, as I want the form to be
maximized or minimized at all times....never Normal.

Is there an easy way to disable the ability to set the form state to Normal
by clicking the Maximize(Restore) button or by double-clicking the window
title bar?

The properties on the taskbar are set to "lock" and "keep on top".

Thanks
 
Hi Paul,

Based on my test, after we call:

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

the window can't be move by draging the title.

Anyway, to disable the Maximize box, you may set the form 's property
"MaximizedBox" to False.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
If you set for forms MaximizedBox property to false, after calling

WindowState = System.Windows.Forms.FormWindowState.Maximized

the window can be dragged.

If the MaximizedBox property is set to true the window cannot be dragged.
 
Hi Paul,

If you don't user move the window when it is maximized, you may add some
code in its Move event, for example:

private void Form1_Move(object sender, System.EventArgs e)
{

this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Top =0;

}

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top