[C# Helper]
Index Books FAQ Contact About Rod
[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]

[Beginning Software Engineering]

[C# 5.0 Programmer's Reference]

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

Title: Find a form's screen in C#

[Find a form's screen in C#]

Find a form's screen can be an issue if the user is using more than one monitor. When this program starts, it uses the following code to get the Screen object that holds the form and display its device name, whether it is the primary screen, and its working area.

private void Form1_Load(object sender, EventArgs e) { Screen screen = Screen.FromControl(this); txtDeviceName.Text = screen.DeviceName; txtIsPrimary.Text = screen.Primary.ToString(); txtWorkingArea.Text = screen.WorkingArea.ToString(); txtDeviceName.Select(0, 0); }

The only non-obvious part of this code is the first statement where the program uses Screen.FromControl to get the Screen object holding the form. The rest of the code is straightforward.

Download the example to experiment with it and to see additional details.

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