简体   繁体   English

获取 UWP 应用程序中所有监视器显示的边界

[英]Get Bounds For All Monitor Displays in UWP Application

How would one go about getting the bounds for each physical display from a UWP application? go 如何从 UWP 应用程序获取每个物理显示器的边界? I used to be able to do this:我曾经能够做到这一点:

System.Windows.Forms.Screen.AllScreens;

I've seen examples using我看过使用的例子

DisplayInformation.GetForCurrentView();

But that only gets the size of the screen the application is currently running on.但这只会获取应用程序当前运行的屏幕大小。 I have a vertical screen application that I'm building and I would like it to always start on my vertical monitor instead of my primary horizontal monitor.我有一个正在构建的垂直屏幕应用程序,我希望它始终在我的垂直显示器而不是我的主水平显示器上启动。 I understand UWP apps should be resolution agnostic, but this isn't the case here.我了解 UWP 应用程序应该与分辨率无关,但这里不是这种情况。 This is an application designed to work on a very particular display.这是一个设计用于在非常特殊的显示器上工作的应用程序。

Please, this is UWP question only.请,这只是 UWP 问题。 This Question was written 6 years before UWP was even a thing.这个问题是在 UWP 出现之前 6 年写的。 This is not a duplicate.这不是重复的。

It indeed seems there is no API that can achieve this currently in UWP. 实际上,UWP中似乎没有API可以实现此目的。 You can post this idea to UWP UserVoice so that it is considered as something you would want. 您可以将此想法发布到UWP UserVoice,以便将其视为您想要的东西。

The best you can do is query the resolution of the monitor the app is running on as you stated and also enumerating all monitors using ProjectionManager : 您能做的最好的事情就是按照您所说的查询应用程序正在运行的监视器的分辨率,并使用ProjectionManager枚举所有监视器:

var deviceSelector = ProjectionManager.GetDeviceSelector();            
var devices = await DeviceInformation.FindAllAsync(deviceSelector);
foreach (var device in devices)
{
    Debug.WriteLine("Kind: {0} Name: {1} Id: {2}", device.Kind, device.Name, device.Id);
    foreach (var property in device.Properties)
    {
        Debug.WriteLine( property.Key + " " + property.Value);
    }
}

Unfortunately the device properties don't contain resolution information that you could use. 不幸的是,设备属性不包含您可以使用的分辨率信息。

You can use code like this您可以使用这样的代码

        var deviceSelector = DisplayMonitor.GetDeviceSelector();
        var devices = await DeviceInformation.FindAllAsync(deviceSelector);

        foreach (var device in devices)
        {
            var monitor = await DisplayMonitor.FromInterfaceIdAsync(device.Id);
            var monitorSize = monitor.NativeResolutionInRawPixels;
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM