Title: 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.
|