【问题标题】:How to easily find screen location of form Location in multi-monitor environment?如何在多显示器环境中轻松找到表单位置的屏幕位置?
【发布时间】:2010-09-08 13:18:04
【问题描述】:

在多显示器环境中运行的 C# winform 应用程序中(桌面横跨 2 或 3 个显示器),Form 的 Location 属性表示窗体在跨区桌面上的位置,而不是窗体在物理上的位置屏幕。对于表单所在的屏幕,是否有一种简单的方法可以在屏幕坐标中找到表单的位置?那么如果表单在第二个或第三个显示的左上角,位置应该是(0,0)?

【问题讨论】:

    标签: c# winforms multiple-monitors


    【解决方案1】:
    /// <summary>Returns the location of the form relative to the top-left corner
    /// of the screen that contains the top-left corner of the form, or null if the
    /// top-left corner of the form is off-screen.</summary>
    public Point? GetLocationWithinScreen(Form form)
    {
        foreach (Screen screen in Screen.AllScreens)
            if (screen.Bounds.Contains(form.Location))
                return new Point(form.Location.X - screen.Bounds.Left,
                                 form.Location.Y - screen.Bounds.Top);
    
        return null;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-02
      • 1970-01-01
      • 1970-01-01
      • 2012-08-24
      • 2013-07-31
      • 2020-06-07
      相关资源
      最近更新 更多