检查第二台显示器是否已连接到 .NET(双显示器设置、带有扩展坞的笔记本电脑)
问题是:
我有一个应用程序(C#.NET、Windows 7),它会记住退出时主窗体的位置。加载时,将检索并应用设置。我对运行双显示器设置的用户有疑问。
我们主要使用带有扩展坞和辅助显示器的惠普笔记本电脑。用户有时必须拔出笔记本电脑。当用户在辅助显示器上运行应用程序,然后将其关闭,断开笔记本电脑的连接并重新启动该应用程序时 - 这是越界的(因为应用程序会记住该位置)。
我需要一种方法来查看第二个显示器是否已连接。
这是我已经尝试过的:
System.Windows.Forms.Screen.AllScreens - 即使笔记本电脑未连接,该阵列也有两个显示器(我认为这是因为第二个显示器仍然显示在控制面板中 ->显示)
System.Windows.Forms.SystemInformation.MonitorCount - 这同样适用于此属性。
谢谢。
谢谢大家,但在这种情况下,我们的笔记本电脑存在以下问题:
我们在笔记本电脑上使用 2x 客户端软件来访问服务器上运行的应用程序。 2x 本身在“兼容性”选项卡中有一个“禁用桌面合成”设置。如果选中此选项,则第二个显示器始终可用(即使笔记本电脑未连接坞站)。
因此解决方法是打开此设置。
再次感谢
Here is the problem:
I have an application (C#.NET, Windows 7) that remembers the location of the main form on exit. On load the settings are retrieved and applied. I have a problem with the users that run dual monitors setup.
We mostly use HP laptops with docking stations and secondary monitors. Users sometimes have to undock their laptops. When the user has an application running on a secondary monitor, then shuts it down, undocks the laptop and restarts the application - it is off bounds (since the location is remembered by application).
I need a way to see if the second monitor is connected.
Here is what I have already tried:
System.Windows.Forms.Screen.AllScreens - this array has two monitors even if the laptop is undocked (I assume its due to the fact that the second monitor still shows up in Control Panel -> Display)
System.Windows.Forms.SystemInformation.MonitorCount - the same applies to this property.
Thank you.
Thank you guys, but the problem with our laptops in this case was the following:
We are using 2x client software on our laptops to access the applications that run on the server. 2x itself has a setting Disable Desktop Composition in Compatibility tab. If this is checked off the second monitor always appears to be available (even when the laptop is undocked).
So the fix was to turn this setting on.
Thanks again
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个...如果事情像您所描述的那样糟糕(在控制面板中查看显示器等),它可能没有帮助,但值得一试。将以下方法添加到您的项目中:
然后,当您加载表单的位置时,传递您要加载它的点以及表单的大小。如果表单足够可见以至于用户可以移动它,则该方法将返回 true,否则返回 false。如果是假的,只需将其放在主屏幕上即可。我在我的程序中使用了这个,在扩展坞上使用笔记本电脑,结果完美无缺——但如果你的电脑在不存在的情况下以某种方式报告额外的监视器,我不知道结果会是什么。如果确实如此,我怀疑这是扩展坞(或 Windows...)的问题,并且您可能没有通过代码解决此问题的好方法。
Try this... It may not help if things are as bad as you are describing (seeing the monitor in Control Panel and all), but it's worth a shot. Add the following method to your project:
Then when you load the location of your form, pass the point to which you intend to load it and the size of your form. The method will return true if the form will be visible enough that the user could move it, and false otherwise. If it's false, just put it on the main screen. I use this for my program using a laptop on a docking station with flawless results -- but again if your PC's are somehow reporting extra monitors when they don't exist, I don't know what the results will be. If that's really true, I suspect it's a problem with the docking station (or Windows...), and you might not have a good way around this through code.