Find the Screen object on which a form is running in C#

This is 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.



What did you think of this article?

  • No trackbacks exist for this post.
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.


 Email (will not be published)


Your comment is 0 characters limited to 3000 characters.