I work on VS 2008 with C#. This below code does not work for me. My form was designed in 1024 x 768 resolution.
Our clients laptop is in 1366 x 768 resolution. To solve this problem, I set below code in Form Load event:
this.Location = new Point(0, 0);
this.Size = Screen.PrimaryScreen.WorkingArea.Size;
but the form does not resize as per screen resolution and bottom of my form gets hidden or cut or I miss the scroll bar.
Is there any way to solve this problem? Please show me the syntax. Thanks in advance
You can always tell the window to start in maximized... it should give you the same result... Like this:
this.WindowState = FormWindowState.Maximized;
P.S. You could also try (and I'm not recommending this) to subtract the taskbar height.
Set the form property to open in maximized state.
Probably a maximized Form helps, or you can do this manually upon form load:
Code Block
And then, play with anchoring, so the child controls inside your form automatically fit in your form's new size.
Hope this helps,
Can't you start maximized?
Set the
System.Windows.Forms.Form.WindowState
property toFormWindowState.Maximized
If you want to set the form size programmatically, set the form's
StartPosition
property toManual
. Otherwise the form's own positioning and sizing algorithm will interfere with yours. This is why you are experiencing the problems mentioned in your question.Example: Here is how I resize the form to a size half-way between its original size and the size of the screen's working area. I also center the form in the working area:
Note that setting
WindowState
toFormWindowState.Maximized
alone does not change the size of the restored window. So the window might look good as long as it is maximized, but when restored, the window size and location can still be wrong. So I suggest setting size and location even when you intend to open the window as maximized.You can simply set the window state