How to find on which screen the application works in C #

How to determine which screen my application is running on?

+5
c # screen winforms
Feb 14 '09 at 20:34
source share
5 answers

This should help you get started. Get the button and list on the form and put it in Button_Click:

listBox1.Items.Clear(); foreach (var screen in Screen.AllScreens) { listBox1.Items.Add(screen); } listBox1.SelectedItem = Screen.FromControl(this); 

The answer is on the last line, remember that the form is also a control.

+6
Feb 14 '09 at 20:53
source share

The System.Windows.Forms.Screen class provides this functionality.

For example:

Screen s = Screen .FromPoint (p);

where p is a point somewhere in your application (in screen coordinates).

+1
Feb 14 '09 at 20:52
source share

Hmm, I don’t think there is a built-in way to get this, but it should not be too hard to define. Use the Screen class to find all screens, skip this list and compare its borders with the location of the form.

Here are some unverified codes

 Screen [] screens = Screen.AllScreens; for(index = 0; index < screens.Length; index++) { if (screens[index].Contains(this.Bounds)) return screens[index]; } 
0
Feb 14 '09 at 20:51
source share

Take a look at these links:

This is in WinAPI. There may be .NET library libraries with multiple monitors / api, but if not, you can write your own with them.

0
Feb 14 '09 at 20:54
source share

Well, many years have passed, and it is derived from the accepted answer, but it worked for me. This method is a member of the Form class. The screen variable contains the properties of the screen on which the upper left corner of the form is located when the method is called.

 private void ClsFormFoo_Load(object sender, EventArgs e) { Screen screen = Screen.FromControl(this); } 
0
Jul 23 '19 at 14:41
source share



All Articles