Get the screen’s working area in C#

[working area]

The working area is the part of the screen that an application can normally occupy. This area may be in different parts of the screen depending on the task bar’s size and location. For example, if the task bar is docked to the left side of the screen, the working area will allow room for it.

The Screen.PrimaryScreen.WorkingArea property gives the primary screen’s working area. This example uses the following code to make its form fill the working area minus a 5 pixel margin around the edges.

// Make the form fill the working area.
private void Form1_Load(object sender, EventArgs e)
{
    const int margin = 5;
    Rectangle rect = new Rectangle(
        Screen.PrimaryScreen.WorkingArea.X + margin,
        Screen.PrimaryScreen.WorkingArea.Y + margin,
        Screen.PrimaryScreen.WorkingArea.Width - 2 * margin,
        Screen.PrimaryScreen.WorkingArea.Height - 2 * margin);
    this.Bounds = rect;
}

Normally you probably wouldn’t use this method to make a program fill the entire working area because it would be easier to simply set the form’s WindowState to Maximized. This method might be useful, however, if you want to make the form appear as if it were docked to one of the working area’s edges.


Download Example   Follow me on Twitter   RSS feed   Donate




This entry was posted in system and tagged , , , , , , , , . Bookmark the permalink.

One Response to Get the screen’s working area in C#

  1. Pingback: Position a form in the screen's lower right corner in C# - C# HelperC# Helper

Leave a Reply

Your email address will not be published. Required fields are marked *