How do I determine what screen my application is running on?
Take a look at these links:
These are in WinAPI. There may be .NET multiple monitor libraries/api calls, but if not, with these you can write your own.
This should get you started. Get a Button and a listbox on a Form and put this in the Button_Click:
listBox1.Items.Clear();
foreach (var screen in Screen.AllScreens)
{
listBox1.Items.Add(screen);
}
listBox1.SelectedItem = Screen.FromControl(this);
The answer is in the last line, remember that a Form is a Control too.
Hmm, I don't think there is a built in way to get this, but it shouldn't be too hard to determine. Use the Screen class to find all the screens, loop through that list and compare its bounds with the location of the form.
Here is some untested code
Screen [] screens = Screen.AllScreens;
for(index = 0; index < screens.Length; index++) {
if (screens[index].Contains(this.Bounds))
return screens[index];
}
The System.Windows.Forms.Screen class provides this functionaility.
For example:
Screen s = Screen.FromPoint(p);
where p is a Point somewhere on your application (in screen coordinates).
Well, many years have passed, and it is derivative of the accepted answer, but this worked for me. This method is a member of the Form class. The screen
variable contains the properties of the screen that the upper left corner of the form is on when the method is called.
private void ClsFormFoo_Load(object sender, EventArgs e)
{
Screen screen = Screen.FromControl(this);
}