转换System.Drawing.Font.Size到WPF字号 [英] Convert System.Drawing.Font.Size to WPF FontSize

查看:1948
本文介绍了转换System.Drawing.Font.Size到WPF字号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  myGdiFont作为System.Drawing.Font
 

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

在particularry,我需要转换

  _size = myGdiFont.Size(???)
 

在的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控件的<一个验证这一点href="http://msdn.microsoft.com/en-us/library/system.windows.controls.control.fontsize.aspx">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.

这篇关于转换System.Drawing.Font.Size到WPF字号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆