我如何确定哪些监控我的.NET Windows窗体程序上运行?我的、窗体、程序、Windows

2023-09-02 10:55:32 作者:今天小编给大家带来一组好听流行的男生,一起来瞧一瞧有没有哪个

我有,我要确保,如果用户移动到人会出现第二个显示器上一个C#Windows应用程序。我需要保存主窗体的大小,位置和窗口状态 - 我已经处理 - 但我还需要了解哪些屏幕是当用户关闭应用程序的

I have a C# Windows application that I want to ensure will show up on a second monitor if the user moves it to one. I need to save the main form's size, location and window state - which I've already handled - but I also need to know which screen it was on when the user closed the application.

我使用Screen类来确定当前屏幕的尺寸,但我无法找到如何确定哪个筛选应用程序上运行任何东西。

I'm using the Screen class to determine the size of the current screen but I can't find anything on how to determine which screen the application was running on.

编辑:感谢您的答复,大家好!我想,以确定哪些监测窗子上,所以我可以做正确的边界检查,以防用户不小心把窗口查看区域外或改变屏幕尺寸,其形式不会是完全可见了。

Thanks for the responses, everyone! I wanted to determine which monitor the window was on so I could do proper bounds checking in case the user accidentally put the window outside the viewing area or changed the screen size such that the form wouldn't be completely visible anymore.

推荐答案

您能得到您已使用该code屏幕的数组。

You can get an array of Screens that you have using this code.

Screen[] screens = Screen.AllScreens;

您也可以找出哪个屏幕上,通过运行该code(这是Windows窗体你是)

You can also figure out which screen you are on, by running this code (this is the windows form you are on)

Screen screen = Screen.FromControl(this); //this is the Form class

在短期退房Screen类和静态辅助方法,它们可以帮助你。

in short check out the Screen class and static helper methods, they might help you.

MSDN链接,没有much..I通过自己在code建议瞎搞。

MSDN Link, doesn't have much..I suggest messing around in the code by yourself.