繁体   English   中英

自定义DPI的辅助屏幕的实际分辨率

[英]Actual resolution of secondary screen for custom DPI

我正在努力使应用程序适应自定义DPI值(Windows缩放)。

如果我理解正确,缩放使应用程序思考,分辨率比实际更小。 例如,如果您具有1920x1080分辨率,则具有125%的比例,最大化窗口的实际大小将为1536x864。 当然,如果你从代码中控制一些大小和位置,它可能会导致一些问题。

现在,我正在使用下一个定位值等:

  • SystemParameters.FullPrimaryScreenWidthSystemParameters.FullPrimaryScreenHeight为“虚拟”(缩放)分辨率;
  • Screen.PrimaryScreen.WorkingArea.WidthScreen.PrimaryScreen.WorkingArea.Height用于原始分辨率;

从这个值,很容易获得缩放值,可用于任何定位和大小调整。

但所有这些值实际上都是针对主屏幕的。 如果我需要对辅助屏幕进行定位和调整,如果可能具有不同的实际(因此,不同的“虚拟”)分辨率,该怎么办?

现在我得到这样的屏幕

var screen = Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(Application.Current.MainWindow).Handle);

这允许我使用WorkingArea矩形获得实际分辨率。 但是“虚拟”解决方案呢? 是否有主要的任何屏幕的SystemParameters.FullPrimaryScreenWidth等模拟?

PS。 我知道,这个比例是共享的,所以通过获取主屏幕的值,我可以将它用于任何其他屏幕,但我想知道答案,如果有直接变量来获取这个值,无论如何。

您可以使用以下比率

        // calculates text size in that main window (i.e. 100%, 125%,...)
        var ratio = Math.Max(Screen.PrimaryScreen.WorkingArea.Width / SystemParameters.PrimaryScreenWidth,
                        Screen.PrimaryScreen.WorkingArea.Height / SystemParameters.PrimaryScreenHeight);

例如,如果您想在所有屏幕上显示最大化窗口,则需要使用以下矩形(代码来自App.xaml.cs):

        foreach (var screen in Screen.AllScreens)
        {
            var mainViewModel = container.Resolve<IMainWindowModel>();

            var window = new MainWindow(mainViewModel);
            if (screen.Primary)
                Current.MainWindow = window;

            window.Left = screen.WorkingArea.Left / ratio;
            window.Top = screen.WorkingArea.Top / ratio;
            window.Width = screen.WorkingArea.Width / ratio;
            window.Height = screen.WorkingArea.Height / ratio;
            window.Show();
            window.WindowState = WindowState.Maximized;
        }

此外,您可以查看我的帖子https://ireznykov.com/2017/01/13/wpf-windows-on-two-screens/ ,它指的是在所有屏幕上输出最大化窗口的GitHub示例应用程序。

暂无
暂无

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

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