How to Size the form to Maximum at OnPaint??

  • Thread starter Thread starter Chi Pheo
  • Start date Start date
C

Chi Pheo

Hi all!
I want to know hot to make the form to maximal size (=desktop size) at the
moment of OnPaint?
Thanks in advance!
 
I'm curious, why would you want to do this?

Anyway, the following code is one way to do it (note that the user can still
resize/move the form without OnPaint being fired...so you may want make this
a separate method and call it from the OnPaint, OnMove, and OnResize events.
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs
e)
{
Rectangle rect = Screen.GetWorkingArea(this);
// Only change the size if it is different.
if ( (this.Size.Width != rect.Width) || (this.Size.Height !=
rect.Height) )
{
this.Size = new Size(rect.Width, rect.Height);
}

// I have to assume you want the form to be at position 0,0...this part
will do that.

// Only change the location if it is different.
if ( (this.Location.X != 0) || (this.Location.Y != 0) )
{
this.Location = new Point(0, 0);
}
}

ShaneB
 
Back
Top