【问题标题】:C# Check orientation of second screenC# 检查第二个屏幕的方向
【发布时间】:2019-05-03 10:15:38
【问题描述】:

我已经编写了一个可以旋转我的第三个显示器的代码。

现在我想先检查一下,当前显示的方向是什么。

我写了以下代码:

    int scrRectHeight = Screen.PrimaryScreen.Bounds.Height;
    int scrRectWidth = Screen.PrimaryScreen.Bounds.Width;

    if (scrRectHeight > scrRectWidth)
    {
        Display.Rotate(3, Display.Orientations.DEGREES_CW_90;
    }
    else
    {
        Display.Rotate(3, Display.Orientations.DEGREES_CW_180;
    }

这很好用,但它只适用于主显示器。我找不到将其更改为第二个显示的定义。我该如何更改它,或者有其他方法吗?谢谢!

【问题讨论】:

  • 如果您想查看第二个屏幕 Screen.AllScreens[1] 的属性,请考虑不使用 PrimaryScreen。
  • @HansPassant 我不明白如何使用 AllScreens。就是这么简单!谢谢
  • @HansPassant 你能把它添加为答案以便我标记它吗?
  • 我很难识别这段代码中的大脑错误。只需分享您在自己的帖子中发现的内容并将其标记为答案即可。

标签: c# multiple-monitors


【解决方案1】:

没有“SecondaryScreen”属性。

试试这个:

int secondRectHeight = Screen.AllScreens[1].Bounds.Height;
int secondRectWidth = Screen.AllScreens[1].Bounds.Width;

if (secondRectHeight > secondRectWidth)
{
    Display.Rotate(3, Display.Orientations.DEGREES_CW_90;
}
else
{
    Display.Rotate(3, Display.Orientations.DEGREES_CW_180;
}

【讨论】:

  • 谢谢,但这太复杂了。看看 Hans Passant 的评论。
  • 更新了示例。
猜你喜欢
  • 1970-01-01
  • 2016-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多