[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Get the screen's working area in C#

[Get the screen's working area in C#]

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 the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.