Resizing a form on a specific monitor, before it is visible.

  • Thread starter Thread starter Zytan
  • Start date Start date
Z

Zytan

The following code works if the form is already visible.

Size sizeMon = SystemInformation.PrimaryMonitorSize;
Rectangle virtScrn = SystemInformation.VirtualScreen;
this.Size = sizeMon; // make it full size of one monitor
Point loc = new Point(virtScrn.Left, virtScrn.Top); // put it to the
far left monitor
this.Location = loc;
this.WindowState = FormWindowState.Maximized; // maximize it

But, not inside the c'tor, after InitializeComponent() is called,
before the form is visible. I want it to move before it is visible,
so you can't see it move.

Zytan
 
I should note that this works before it is visible:

// make it full size of one monitor
Size sizeMon = SystemInformation.PrimaryMonitorSize;
this.Size = sizeMon;

And this works before it is visible:

// maximize it
this.WindowState = FormWindowState.Maximized;

It is only this that doesn't work before it is visible:

// put it to the far left monitor
Rectangle virtScrn = SystemInformation.VirtualScreen;
Point loc = new Point(virtScrn.Left, virtScrn.Top);
this.Location = loc;

Zytan
 
It is only this that doesn't work before it is visible:
// put it to the far left monitor
Rectangle virtScrn = SystemInformation.VirtualScreen;
Point loc = new Point(virtScrn.Left, virtScrn.Top);
this.Location = loc;

Solved it thanks to:
http://forums.whirlpool.net.au/forum-replies-archive.cfm/444877.html

stovellp said: "I believe you can set the location in the constructor,
but you need to take special care to position the form manually by
setting the StartPosition property:

this.StartPosition = FormStartPosition.Manual;
this.Location = new Point(
SystemInformation.WorkingArea.Widt­h - Width,
SystemInformation.WorkingArea.Heig­ht - Height); "

Zytan
 
Back
Top