tags:

views:

292

answers:

4

How do I determine what screen my application is running on?

A: 

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];
}
Bob
screens.Contains() -is what you are after and if so you dont need to look though them....
cgreeno
+1  A: 

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).

Ash
+4  A: 

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.

Henk Holterman
+1 for an answer simpler than mine
Bob
A: 

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.

Tommy Hui