如何获取屏幕方向?

3

我正在输入要显示表单的屏幕编号。我必须获取屏幕方向。有人知道如何做吗?

 public UIManager(int screenIndex)
    {
        this.ScreenIndex = screenIndex;            

        try
        {
            Screen[] all_screens;
            all_screens = Screen.AllScreens;

            if (all_screens.Length >= ScreenIndex)
            {
                this.customer_form.Left = all_screens[this.ScreenIndex].Bounds.Width;
                this.customer_form.Top = all_screens[this.ScreenIndex].Bounds.Height;                    
                this.customer_form.Show();
            }
        }
        catch
        {
            //Do nothing
        }
    }

4
你的意思是纵向和横向的区别吗?在这种情况下,请查看哪个维度更大。但请记住,也有方形屏幕存在。 - Richard
如果我没错的话,您需要 P/Invoke EnumDisplaySettings,并使用 DEVMODEdmDisplayOrientation - Sriram Sakthivel
为什么不直接使用 SystemInformation.SceenOrientation - Matthew Watson
这可能会有所帮助 https://dev59.com/bFjUa4cB1Zd3GeqPT7ZO#6510861 - kenny
1个回答

7
您可以使用从 Windows.Graphics.Display.DisplayInformation 返回的值,该值由 DisplayInformation.getForCurrentView() 和其 currentOrientation 属性 返回:
 DisplayOrientations currentOrientation = Windows.Graphics.Display.DisplayProperties.CurrentOrientation;

来自官方文档: DisplayOrientations枚举

该枚举表示设备屏幕的朝向。可以使用以下值之一:


@Pepinho 我怀疑你可能缺少一个引用的 DLL,请查阅 API 文档。 - kenny

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接