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

前端 未结 5 582
一生所求
一生所求 2020-12-11 06:05

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

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-11 07:00

    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];
    }
    

提交回复
热议问题