屏幕分辨率不匹配Screen.Bounds

问题描述:

我看到,它通过控制面板设置分辨率和Screen.Bounds为我宽屏笔记本电脑的输出之间的一个有趣的差异。屏幕是15.5,并通过控制面板设定的分辨率是1920×1080。然而,当我运行像这样的代码。

I am seeing an interesting difference between the resolution that is set through Control Panel and the output of Screen.Bounds for my widescreen laptop. The screen is 15.5" and the resolution set through Control Panel is 1920x1080. However when I run some code like this.

Screen[] screens = Screen.AllScreens;
foreach (Screen scr in screens)
{
    Console.WriteLine("Width: " + scr.Bounds.Width + ", Height: " + scr.Bounds.Width);
}

输出显示我的分辨率为1536x864我已经做了。有的东张西望,而且我认为这可能与一个DPI问题,当我看着我的显示设置,滑块(我是在Windows 8.1)是在中间,并指出勾选让我选择一个换算。我所有的显示器电平选中我跑这少的代码来获得当前的DPI设置

The output shows my resolution being 1536x864. I have done some looking around, and I thought it may be related to a DPI issue, and when I look at my display settings, the slider (I am on Windows 8.1) is in the middle, and the checkbox that states "Let me choose one scaling level for all my displays" is unchecked. I ran this little code to get the current DPI setting.

float dpiX, dpiY;
Graphics graphics = new System.Windows.Forms.Form().CreateGraphics();
Console.WriteLine("DPI: " + graphics.DpiX);

返回的DPI是96.0它通过我的理解是100%的DPI设置(所以没有扩大或不管它被调用)。似乎有什么奇怪,我是,通过屏幕返回的边界是我的实际分辨率,这让我觉得我的DPI设置为100(或125%)正好80%,但事实并非如此。我只是有我的笔记本电脑屏幕这个问题,因为我的辅助监视器有等于通过控制面板分辨率界限。这是由于事实证明我的DPI设置未设置有独立显示的海誓山盟(即复选框选中)?背景一点点,我写一个工具,它当前的屏幕和reddit的获取图像,并将其适合于屏幕互不影响,所以我有什么解决方案,它正确地获得每个显示器的分辨率。

The DPI that is returned is 96.0 which by my understanding is the 100% DPI setting (so no enlargement or whatever it is called). What seems odd to me is that the bounds returned by Screen is exactly 80% of my actual resolution, which would make me think my DPI is set to 100 (or 125%) but it is not. I am only having this issue with my laptop screen, as my secondary monitor has bounds that are equal to resolution through Control Panel. Is this due to the fact that my DPI setting is not set to have the displays independent of eachother (that checkbox checked)? For a little bit of background, I am writing a tool that takes the current screens and gets pictures from reddit and fits them to the screens independently of each other, so whatever solution I have, it has to correctly get the resolution of each display.

我相信你有通知操作系统您的应用程序是DPI意识。否则,OS假装一切都蛮好,导致你观察的行为 - 操作系统处理大小调整

I believe you have to notify the operating system that your application is DPI aware. Otherwise the OS pretends that everything is just fine, leading to the behaviour you're observing - the OS handles the resizing.

您可以找到有关编写DPI感知应用程序的一些信息在这里 - http://msdn.microsoft.com/cs-cz/library/dd464646的.aspx 当然,你应该确保你的应用程序实际上的的DPI知道 - 如果不是,你最好坚持使用默认。它不是很好,但至少它的工作。

You can find some information about writing DPI aware applications here - http://msdn.microsoft.com/cs-cz/library/dd464646.aspx Of course, you should make sure your application actually is DPI aware - if not, you better stick with the default. It's not as nice, but at least it will work.

这是Windows 8.1提请本的主要区别是,你可以在不同的显示器不同的DPI,并且可以查询监控DPI API。 .NET(特别是WPF)默认情况下自动处理DPI意识,而只是基于系统DPI。如果您的显示器有不同的DPI设置,它的行为就非DPI感知(更准确地说,系统DPI感知,但最终的结果是你的应用程序图形将被Windows虚拟化)。我期望,如果你断开你的第二个显示器,您的应用程序会表现你唯一的显示屏(至少后手动设置DPI,无论值)的预期。

The main difference that Windows 8.1 brought to this is that you can have different DPI on different monitors, and you can query the monitor DPI API. .NET (and especially WPF) by default handles DPI awareness automatically, but only based on system DPI. If your monitors have different DPI settings, it will behave as non-DPI-aware (more precisely, system-DPI-aware, but the end result is your applications graphics are going to be virtualized by Windows). I'd expect that if you disconnect your second display, your application would behave as expected on your sole display (at least after manually setting the DPI, whatever the value).