ali raza

C#, .Net ,Asp.net and my thoughts

How to fix the size of windows form at different monitor resolution

Some time developer/coder have to choose appropriate location of windows form on the screen, But limitation comes with the size and resolution of monitor. The solution is used Screen Class which gives right gives you working area of screen of monitor. Then Form load Event will look like this

private void dynamicSizeForm_Load(System.Object sender, System.EventArgse)
{
Screen scr = Screen.PrimaryScreen;
this.Left = (scr.WorkingArea.Width – this.Width) / 2;
this.Top = (scr.WorkingArea.Height – this.Height) / 2;
}
You can use above code to fix the location and size of windows form when it loads

Screen.PrimaryScreen 

Returns a Rectangle structure that represents the bounds
of the display area for the current screen, minus the space
taken for the taskbar and any other docked windows.

2 responses to “How to fix the size of windows form at different monitor resolution

  1. Bhavesh August 1, 2008 at 3:26 pm

    the above code only fixes location of the form, size is not fixed

  2. Suru October 1, 2008 at 9:04 pm

    This code fixes a form:

    this.MinimumSize = new Size(this.Width, this.Height);
    this.MaximumSize = new Size(this.Width, this.Height);

    Place it in onload event and the size will be fixed.

    Happy Coding.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: