Posts Tagged ‘Rectangle’

How to change form size depending on screen resolution?

June 1, 2009

Suppose the screen resolution in which you design the form is 1024*768 then

Rectangle r = Screen.GetBounds(this);

this.Location = new Point(0, 0);

this.Size = r.Size;

double PercWidthChng = (r.Width – 1024);

PercWidthChng /= 1024;

double PercHeightChng = (r.Height – 768);

PercHeightChng /= 768;

 

foreach (Control c in this.Controls)

{

   double NewWidth = c.Width + (c.Width * PercWidthChng);

   double NewHeight = c.Height + (c.Height * PercHeightChng);

   double NewX = c.Location.X + (c.Location.X * PercWidthChng);

   double NewY = c.Location.Y + (c.Location.Y * PercHeightChng);

   double fontsize = c.Font.Size + (c.Font.Size * PercHeightChng);

   c.Width = (int)Math.Floor(NewWidth);

   c.Height = (int)Math.Floor(NewHeight);

   c.Location = new Point((int)NewX, (int)NewY);

   c.Font = new Font(c.Font.FontFamily, (int)fontsize, c.Font.Style);

}

Udhaya