Convert System.Drawing.Font.Size to WPF FontSize

▼魔方 西西 提交于 2019-12-22 05:46:07

问题


I need to convert a GDI Font in a WPF "Font".

myGdiFont As System.Drawing.Font

in

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

In particularry, I need to Convert

_Size = myGdiFont.Size (???)

The size in WinForms font is in Units or Points... In WPF is in Pixels... How to convert from one to another?

PS.
Follwing the Clemens indications, is it correct?

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

Fixed:

  myWpfLabel.FontSize = myDrawingFont.SizeInPoints * 96 / 72

回答1:


By multiplication. A point is 1/72th of an inch, whereas WPF device-independent units ("WPF pixels") are 1/96th of an inch.

You can verify this by specifying a WPF control's FontSize property in XAML as for example "24" and "18pt". You will realize that both values result in the same actual font size.



来源:https://stackoverflow.com/questions/9700753/convert-system-drawing-font-size-to-wpf-fontsize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!