【问题标题】:Convert System.Drawing.Font.Size to WPF FontSize将 System.Drawing.Font.Size 转换为 WPF FontSize
【发布时间】:2012-03-30 20:10:48
【问题描述】:

我需要在 WPF“字体”中转换 GDI 字体。

myGdiFont As System.Drawing.Font

_Family As Windows.Media.FontFamily
_Style As Windows.FontStyle
_Weight As Windows.FontWeight
_Size As Double

特别是,我需要转换

_Size = myGdiFont.Size (???)

WinForms 字体中的大小是单位或点...在 WPF 中是像素...如何从一种转换为另一种?

附言。
按照 Clemens 的指示,是否正确?

  Dim myDrawingFont As New System.Drawing.Font("Arial", 10)
  Dim myWpfLabel As New Windows.Controls.Label
  myWpfLabel.FontSize = myDrawingFont.SizeInPoints * 72 / 96

固定:

  myWpfLabel.FontSize = myDrawingFont.SizeInPoints * 96 / 72

【问题讨论】:

    标签: .net wpf winforms fonts font-size


    【解决方案1】:

    乘法。一个点是 1/72 英寸,而 WPF 设备无关单位(“WPF 像素”)是 1/96 英寸。

    您可以通过在 XAML 中指定 WPF 控件的 FontSize 属性来验证这一点,例如“24”和“18pt”。您将意识到这两个值会产生相同的实际字体大小。

    【讨论】:

    • 不,应该是myWpfLabel.FontSize = myDrawingFont.SizeInPoints / 72 * 96
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-17
    相关资源
    最近更新 更多