vb.netunicodeprintdocument

How to render extended unicode character in PrintPreviewDialog


I want to display 🡸 (a WIDE-HEADED LEFTWARDS HEAVY BARB ARROW Symbol) in a PrintDocument. It does not render correctly; it only shows a box. Using Windows Forms with vb.net 4.6; Visual Studio 2017.

I know I have the correct character and font because it displays in a button just fine on the form. Yet in the PrintPreviewDialog it won't render correctly. What do I need to do?

Public WithEvents Doc As New PrintDocument

Public Sub ShowDialog()

    'page settings
    Me.Doc.DefaultPageSettings = ... set letter size, default printer, margins
    Me.Doc.PrinterSettings = ...default printer
    Me.Doc.DefaultPageSettings.PaperSize.RawKind = PaperKind.Letter
    
    'show dialog
    Dim dlgPreview As New PrintPreviewDialog
    dlgPreview.Document = Me.Doc
    dlgPreview.WindowState = FormWindowState.Maximized
    dlgPreview.ShowDialog()

End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles Doc.PrintPage

    Dim arrow As String = Char.ConvertFromUtf32(&H1F87A)
    Dim f As New System.Drawing.Font("Microsoft Sans Serif", 11, FontStyle.Regular)
    e.Graphics.DrawString(arrow, f, Brushes.Black, 100, 100)

End Sub

Solution

  • By looping through all my installed fonts I was able to find a font that displays the correct character. In my case it was "Segoe UI Symbol".