Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find what screen the application is running on in C#

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

like image 348
Brad Avatar asked Feb 14 '09 20:02

Brad


2 Answers

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.

like image 56
Henk Holterman Avatar answered Oct 01 '22 00:10

Henk Holterman


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

like image 42
Ash Avatar answered Sep 30 '22 22:09

Ash