7

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 Answer 1

10

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.

Sign up to request clarification or add additional context in comments.

1 Comment

No, it should be myWpfLabel.FontSize = myDrawingFont.SizeInPoints / 72 * 96.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.