我已经好好Screen.PrimaryScreen.Bounds.Size待了一段时间,但在连接到我的大屏幕电视的Windows7电脑上,它给了我不正确的价值.
我在其他地方读过尝试,SystemInformation.PrimaryMonitorSize但是给出了相同的值.
当我右键单击桌面以获得屏幕分辨率时,它说1920x1080.以上两个给了我1280x720.
我也试过WPF版本:
var w = System.Windows.SystemParameters.PrimaryScreenWidth;
var h = System.Windows.SystemParameters.PrimaryScreenHeight;
MessageBox.Show(new Size((int)w, (int)h).ToString());
Run Code Online (Sandbox Code Playgroud)
显示尺寸已通过(右键单击桌面)Personalize > Desktop选项更改为150%(因为屏幕为60"并且您坐得很远).
如何检测这个,以便从上面返回的值可以调整?
注意:我已经发现如何通过右键单击可执行文件来解决这个问题并调整兼容性以禁用DPI虚拟化,但我仍然需要一个编程解决方案,所以我不必让用户自己调整它:请参阅 - http: //msdn.microsoft.com/en-us/library/dd464660(VS.85).aspx#dpi_virtualization
它可能是你Dpi设置在100%以上的窗口
尝试使用此方法,这会将分辨率缩放到当前系统Dpi设置
的WinForms:
private Size GetDpiSafeResolution()
{
using (Graphics graphics = this.CreateGraphics())
{
return new Size((Screen.PrimaryScreen.Bounds.Width * (int)graphics.DpiX) / 96
, (Screen.PrimaryScreen.Bounds.Height * (int)graphics.DpiY) / 96);
}
}
Run Code Online (Sandbox Code Playgroud)
WPF:
private Size GetDpiSafeResolution()
{
PresentationSource _presentationSource = PresentationSource.FromVisual(Application.Current.MainWindow);
Matrix matix = _presentationSource.CompositionTarget.TransformToDevice;
return new Size(SystemParameters.PrimaryScreenHeight * matix.M11, SystemParameters.PrimaryScreenWidth * matix.M22);
}
Run Code Online (Sandbox Code Playgroud)
注意:在运行此代码之前,请确保已加载MainWindow
我不认为这是一个重复的问题,但答案与另一个线程相同:/sf/answers/925994681/ 因为问题不是关于模糊字体,而是关于 Screen.PrimaryScreen。 Bounds.Size 返回错误信息。它可以帮助其他人。
我确实遇到了一条错误消息,即 mscorlib 引发了空错误。从这个线程http://forums.asp.net/t/1653876.aspx/1我发现取消选中“启用ClickOnce安全设置”可以修复它。这看起来像是一个 hack,但它确实有效。