我需要将 GDI 字体转换为 WPF“字体”。
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 中以像素为单位...如何从一种转换为另一种?
附注。
遵循克莱门斯的指示,正确吗?
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
最佳答案
通过乘法。点是 1/72 英寸,而 WPF 设备独立单位(“WPF 像素”)是 1/96 英寸。
您可以通过指定 WPF 控件的 FontSize 来验证这一点XAML 中的属性,例如“24”和“18pt”。您将意识到这两个值都会产生相同的实际字体大小。
关于.net - 将 System.Drawing.Font.Size 转换为 WPF FontSize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9700753/