转换System.Drawing.Font.Size到WPF字号字号、Drawing、System、Font

2023-09-03 22:13:21 作者:杀我别用感情刀

我需要转换一个GDI字体在WPF字体。

  myGdiFont作为System.Drawing.Font
 

  _Family作为Windows.Media.FontFamily
_style作为Windows.FontStyle
_Weight作为Windows.FontWeight
_size作为双
 

在particularry,我需要转换

  _size = myGdiFont.Size(???)
 
rstudio中文破解版下载 v1.4.1106 免费版

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

PS。 Follwing的克莱门斯的迹象,是正确的吗?

 昏暗myDrawingFont作为新System.Drawing.Font(宋体,10)
  昏暗myWpfLabel作为新Windows.Controls.Label
  myWpfLabel.FontSize = myDrawingFont.SizeInPoints *九十六分之七十二
 

修正:

  myWpfLabel.FontSize = myDrawingFont.SizeInPoints *七十二分之九十六
 

解决方案

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

您可以通过指定一个WPF控件的FontSize财产XAML的如24和18pt。您会认识到,这两个值导致相同的实际字体大小。

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

解决方案

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.