So, I've wrote a program awhile ago that prints barcode labels. The old version needed the font to be installed in the fonts folder, but that made it a pain for people using the program for the first time, as the program would print the barcode label with a default font. If I load the font file directly and try and print, it just shows up with the default font, obviously not a barcode. The following doesn't seem to work:
Private Sub Print_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim pointF As New PointF(0, 0)
Dim drawFormat As New StringFormat
drawFormat.FormatFlags = StringFormatFlags.DirectionVertical
Dim drawBrush As New SolidBrush(Color.Black)
' Install and size the font
Dim barcodeFont As Font
Dim barcodeFontSize = 36
Dim pfc As New PrivateFontCollection
pfc.AddFontFile("FRE3OF9X.TTF")
barcodeFont = New Font(pfc.Families(0), barcodeFontSize)
e.Graphics.DrawString(serial, barcodeFont, drawBrush, pointF, drawFormat)
' There are no more pages.
e.HasMorePages = False
End Sub
This is the old way, and it does work:
Private Sub Print_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim pointF As New PointF(0, 0)
Dim drawFormat As New StringFormat
drawFormat.FormatFlags = StringFormatFlags.DirectionVertical
Dim drawBrush As New SolidBrush(Color.Black)
' Install and size the font
Dim barcodeFont As Font
Dim barcodeFontSize = 36
barcodeFont = New Font("Free 3 of 9 Extended", barcodeFontSize)
e.Graphics.DrawString(serial, barcodeFont, drawBrush, pointF, drawFormat)
' There are no more pages.
e.HasMorePages = False
End Sub
I've loaded this font into a font family and successfully printed a barcode text onto a picture box. For some reason the same process doesn't work here. I was thinking of creating a bitmap and then printing the bitmap, but that seems very round-a-bout.