标准" WPF字体大小和&QUOT转换;字体大小 [英] Converting between WPF font size and "standard" font size

查看:399
本文介绍了标准" WPF字体大小和&QUOT转换;字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到WPF中,12分的默认字体大小大致相当于在正常的应用程序得到9分(如写字板),10磅的WPF大约7磅的标准,当我尝试匹配10磅在写字板WPF中默认的字体大小,我发现13是最接近的。

I've noticed in WPF, the default font size of 12 points is roughly equivalent to 9 points in "normal" applications (e.g. WordPad), 10 pt in WPF is roughly 7 pt standard, and when I try to match the default font size of 10 pt in WordPad in WPF, I've found 13 is the closest.

首先,为什么WPF使用这种离奇的非标准字体大小,其次,有没有在两者之间转换一种可靠的方法?

First of all, why does WPF use such bizarre non-standard font sizes, and secondly, is there a reliable way to convert between the two?

我之所以问的是我想建立与9,10,12,14,16,18,24,36,48,但我pretty的标准字体大小确定的字体大小菜单如果我使用的实际值,他们会疯狂地掉。

My reason for asking is I want to build a font size menu with "standard" font sizes of 9, 10, 12, 14, 16, 18, 24, 36, 48, but I'm pretty sure if I use those actual values they will be wildly off.

推荐答案

WPF使用像素为的字体大小点(可能是你,当你说标准字号的意思)的像素是: 1磅=(七十二分之九十六)PX

WPF uses pixels as its default unit for font size. The mapping between points (probably what you mean when you say "standard" font size) and pixels is: 1 pt = (96/72) px

这给了我们一个简单的转换功能:

This gives us a simple conversion function:

public static double PointsToPixels(double points)
{
    return points*(96.0/72.0);
}

请参阅<一href="http://stackoverflow.com/questions/139655/how-to-convert-pixels-to-points-px-to-pt-in-net-c">this问题更多的细节。

这篇关于标准&QUOT; WPF字体大小和&QUOT转换;字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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