Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert System.Drawing.Font.Size to WPF FontSize

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
like image 953
serhio Avatar asked Mar 14 '12 11:03

serhio


1 Answers

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.

like image 182
Clemens Avatar answered Sep 20 '22 16:09

Clemens