屏幕分辨率的问题在WPF? [英] Screen Resolution Problem In WPF?
问题描述
我要检测与下面code在WPF分辨率:
I'm gonna detect the resolution with the following code in WPF :
double height = System.Windows.SystemParameters.PrimaryScreenHeight;
double width = System.Windows.SystemParameters.PrimaryScreenWidth;
我的屏幕的当前的分辨率是1920 * 1200,但 高
为960.0和 宽度
是1536.0!
Current resolution of my screen is 1920*1200, but height
is 960.0 and width
is 1536.0 !!!
有什么不对呢?
先谢谢了。
What's wrong with it ?
Thanks in advance.
推荐答案
请记住,所有的WPF的位置和大小的浮点运算以1/96英寸为单位。不是像素。这使得独立的窗口设计的分辨率。做数学:身高=九十六分之九百六十〇= 10英寸。与您的视频适配器设置为120 DPI(九十六分之一百二十○= 125%):10 * 120 = 1200像素。相同的宽度:1536/96 * 120 = 1920像素
Keep in mind that all WPF locations and sizes are floating point with a unit of 1/96 inch. Not pixels. This makes your window designs resolution independent. Doing the math: height = 960 / 96 = 10 inches. With your video adapter set to 120 DPI (120/96 = 125%): 10 * 120 = 1200 pixels. Same for width: 1536 / 96 * 120 = 1920 pixels.
System.Windows.Forms的工作以像素单位。你得到不到1050的高度,因为它减去了任务栏的高度。但是对于WPF你总是希望有1/96的工作,从未像素。
System.Windows.Forms works in units of pixels. You are getting less than 1050 for the height because it subtracts the height of the taskbar. But for WPF you always want to work with 1/96", never pixels.
这篇关于屏幕分辨率的问题在WPF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!