Converting between WPF font size and “standard” font size

后端 未结 2 512
太阳男子
太阳男子 2021-02-05 04:12

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

相关标签:
2条回答
  • 2021-02-05 04:29

    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);
    }
    

    See this question for more details.

    0 讨论(0)
  • 2021-02-05 04:37

    Another method for conversion if you're going from point to WPF double is to use the System.Windows.FontSizeConverter class:

    double sizeForWpf = (double) new FontSizeConverter().ConvertFrom("10pt");
    
    0 讨论(0)
提交回复
热议问题