检查第二台显示器是否在.net中连接(双显示器设置,笔记本电脑与坞站)

本文关键字:显示器 设置 双显示 笔记本 连接 电脑 net 二台 是否 检查 | 更新日期: 2023-09-27 18:03:17

问题是:

我有一个应用程序( c#。. NET, Windows 7)在退出时记住主窗体的位置。加载时检索并应用设置。我对使用双显示器设置的用户有一个问题。

我们大多使用带有坞站和二级显示器的惠普笔记本电脑。用户有时不得不断开笔记本电脑的连接。当用户在辅助监视器上运行应用程序,然后关闭它,卸载笔记本电脑并重新启动应用程序时,这是off bounds(因为该位置被应用程序记住了)。

我需要一种方法来查看第二个监视器是否连接。


这是我已经尝试过的:

System.Windows.Forms.Screen。AllScreens -这个数组有两个显示器,即使笔记本电脑没有连接(我认为这是由于第二个显示器仍然显示在控制面板->显示)

System.Windows.Forms.SystemInformation。MonitorCount -同样适用于此属性。

谢谢。


谢谢你们,但是我们的笔记本电脑在这种情况下的问题是:

我们在笔记本电脑上使用2x客户端软件来访问在服务器上运行的应用程序。2x本身在兼容性选项卡中有一个禁用桌面合成的设置。如果勾选此项,则第二台显示器似乎总是可用的(即使笔记本电脑没有连接)。

所以解决方法是打开这个设置。

再次感谢

检查第二台显示器是否在.net中连接(双显示器设置,笔记本电脑与坞站)

试试这个…如果事情像你描述的那样糟糕(在控制面板中看到显示器等等),这可能没有帮助,但值得一试。将以下方法添加到项目中:

  /// <summary>
  /// Returns whether at least the titlebar of a form would be on a viewable portion of the screen
  /// </summary>
  /// <param name="FormLocation">The location of the form</param>
  /// <param name="FormSize">The size of the form</param>
  /// <returns></returns>
  protected bool FormWouldBeVisible(Point FormLocation, Size FormSize)
  {
     //The FromPoint method returns the screen OR CLOSEST SCREEN to the point you give...
     Screen theScreen = Screen.FromPoint(FormLocation);
     int titleBar = SystemInformation.CaptionHeight;
     //Test if enough of the title bar will be visible so that the user can move the form if desired...
     if ((theScreen.Bounds.Bottom >= (FormLocation.Y + titleBar)) && //If the bottom of the screen is below the title bar
           (theScreen.Bounds.Top <= FormLocation.Y) && //If the top of the screen is above the top of the title bar
           (theScreen.Bounds.Left <= (FormLocation.X + FormSize.Width - titleBar)) && //If the left of the screen is left of a little bit of the title bar
           (theScreen.Bounds.Right >= (FormLocation.X + titleBar))) //If the right of the screen is right of a little bit of the title bar
     {
        //The form is moveable
        return true;
     }
     //The point at which the form is to be loaded is not on a visible part of any screen
     else return false;
  }

然后,当您加载窗体的位置时,传递要加载它的点和窗体的大小。如果表单足够可见,用户可以移动它,该方法将返回true,否则返回false。如果为假,就把它放在主屏幕上。我把笔记本电脑放在一个坞站上,用它来编写我的程序,结果完美无瑕——但如果你的电脑在不存在显示器的情况下报告了额外的显示器,我不知道结果会是什么。如果这是真的,我怀疑这是坞站(或Windows…)的问题,您可能没有通过代码解决这个问题的好方法。