hello. I have tested many fonts but one that I need (a barcode 128 to download here: http://www.jtbarton.com/Barcodes/code128.ttf ) does not work with DrawString. I tried with encoded barcode128 code as well as with regular string. In both examples it works in Word, Excel, also font after being install comes out as tru type font. I am confused why it wont work with VB (it simple shows Arial font instead).
Here is my code:
Any help will be gladly appreciated!!
Thank you
Here is my code:
VB.NET:
Dim bm As New Bitmap(1256, 256)
Dim gr As Graphics = Graphics.FromImage(bm)
Dim barcodeFontSize As Integer = 40
Dim numericFontSize As Integer = 12
gr.SmoothingMode = Drawing2D.SmoothingMode.None
gr.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit
Dim pfc As PrivateFontCollection = New PrivateFontCollection
pfc.AddFontFile("c:/windows/fonts/code128.ttf")
Dim barcodeText As String = "aaaaaacxcjwedhqwsidasd"
gr.Clear(Color.White)
Dim ff As FontFamily = pfc.Families(0)
Dim f As New Font(ff, barcodeFontSize)
gr.DrawString(barcodeText, f, Brushes.Black, 10, 10)
bm.Save("c:\test.gif", ImageFormat.Gif)
'... I also tried without adding font this way:
Dim fontFamily As New FontFamily("Code 128")
Dim fn As New Font(fontFamily, 36, FontStyle.Bold, GraphicsUnit.Point)
gr.DrawString("aaaaaacxcjwedhqwsidasd", fn, Brushes.Black, 15, 10)
'.. but also just plain Arial comes out.
Thank you
Last edited by a moderator: