Find a form’s screen in C#

[screen]

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 Example   Follow me on Twitter   RSS feed   Donate




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

Leave a Reply

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