[c#] How to fit Windows Form to any screen resolution?

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

This question is related to c# winforms c#-3.0 desktop-application

The answer is


Set the form property to open in maximized state.

this.WindowState = FormWindowState.Maximized;

simply set Autoscroll = true for ur windows form.. (its not good solution but helpful)..

try for panel also(Autoscroll property = true)


You can simply set the window state

this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

If you want to set the form size programmatically, set the form's StartPosition property to Manual. 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:

public MainView()
{
    InitializeComponent();

    // StartPosition was set to FormStartPosition.Manual in the properties window.
    Rectangle screen = Screen.PrimaryScreen.WorkingArea;
    int w = Width >= screen.Width ? screen.Width : (screen.Width + Width) / 2;
    int h = Height >= screen.Height ? screen.Height : (screen.Height + Height) / 2;
    this.Location = new Point((screen.Width - w) / 2, (screen.Height - h) / 2);
    this.Size = new Size(w, h);
}

Note that setting WindowState to FormWindowState.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 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.


Probably a maximized Form helps, or you can do this manually upon form load:

Code Block

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

this.Size = Screen.PrimaryScreen.WorkingArea.Size;

And then, play with anchoring, so the child controls inside your form automatically fit in your form's new size.

Hope this helps,


int h = Screen.PrimaryScreen.WorkingArea.Height;
int w = Screen.PrimaryScreen.WorkingArea.Width;
this.ClientSize = new Size(w , h);

Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to winforms

How to set combobox default value? Get the cell value of a GridView row Getting the first and last day of a month, using a given DateTime object Check if a record exists in the database Delete a row in DataGridView Control in VB.NET How to make picturebox transparent? Set default format of datetimepicker as dd-MM-yyyy Changing datagridview cell color based on condition C# Inserting Data from a form into an access Database How to use ConfigurationManager

Examples related to c#-3.0

how to check if string value is in the Enum list? Label word wrapping how to insert datetime into the SQL Database table? How to fit Windows Form to any screen resolution? C# adding a character in a string How to dynamic new Anonymous Class? How to get index using LINQ? System.Drawing.Image to stream C# AddRange to a Collection Metadata file '.dll' could not be found

Examples related to desktop-application

How to develop Desktop Apps using HTML/CSS/JavaScript? How to fit Windows Form to any screen resolution? Executable directory where application is running from?