C#WPF分辨率independancy? [英] C# WPF resolution independancy?

查看:125
本文介绍了C#WPF分辨率independancy?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发展在WPF地图控制与C#。我使用的是帆布例如控制400×200被分配的例如地图区域。2,000mx千米



该地图的比例应该是: canvas_size_in_meters / real_size_in_meters



我想找到canvas_size_in_meters。



canvas.ActualWidth给出了打倒帝国主义同盟的(设备独立单位)的宽度。因此,400 DIU的是96分之400= 4,17英寸,提供的物理解决我的显示器是96 dpi的。



然而,使用一个统治者,我发现我的显示器物理分辨率为87 dpi的。 (有,实际上只有几台显示器96个物理DPI)



这DPI差(10%)转换为在屏幕上的实际地图控制宽度为+ 10%的差异



我如何衡量英寸的WPF控件的大小准确,不论屏幕分辨率和DPI设置?


解决方案

我如何衡量英寸的WPF控件的大小准确,不论屏幕分辨率和DPI设置?




这实际上是不可能的,因为它的工作,WPF必须知道分辨率(DPI中计)显示器。在理论上听起来不错,但在实践中Windows不知道这个信息。这就是为什么Windows本身总是假定96DPI盲目,而不是被它更聪明。



即使有某种方式来手动告诉它,或者,如果您的特定的显示器具有自定义驱动程序,做传递正确的信息窗口,这是不会对任何人的电脑上工作,所以Windows不传递任何应用程序的信息。



你能做的最好是画一个类似规模的谷歌地图一样。你知道1的像素的== 1英里,所以你可以画在地图上50像素的线,一个标签说:这行等于50里


I am developing a map control in WPF with C#. I am using a canvas control e.g. 400 x 200 which is assigned a map area of e.g. 2,000m x 1,000m.

The scale of the map would be: canvas_size_in_meters / real_size_in_meters.

I want to find the canvas_size_in_meters.

The canvas.ActualWidth gives the Width in DIU's (Device Independant Units). So, 400 DIU's is 400/96 = 4,17 inches, PROVIDED that the physical resolution of my monitor is 96 dpi.

However, using a ruler, I found that the physical resolution of my monitor is 87 dpi. (There are only few monitors that ACTUALLY have 96 physical dpi)

That DPI difference (10%) translates to a +10% difference in the actual map control width on screen.

How do I measure the size of a WPF control in inches EXACTLY and regardless of screen resolution and DPI setting ?

解决方案

How do I measure the size of a WPF control in inches EXACTLY and regardless of screen resolution and DPI setting ?

This isn't actually possible, because for it to work, WPF would have to know the resolution (in terms of DPI) of your monitor. Sounds nice in theory, but in practice windows doesn't know this information. This is why windows itself always assumes 96dpi blindly instead of being smarter about it.

Even if there were some way to manually tell it, or if your particular monitor has a custom driver that does pass the correct information to windows, this isn't going to work on anyone else's computer, so windows doesn't pass this information on to any applications.

The best you can do is draw a scale like google maps does. You know that 1 pixel == 1 mile, so you can draw a 50 pixel line on your map, with a label saying "this line equals 50 miles"

这篇关于C#WPF分辨率independancy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆