I am trying to print a barcode
I have successfully made the barcode in a label using a reference .dll file
Imports BarCode
TempLabel = New Label
With TempLabel
.Text = BarcodeConverter128.StringToBarcode(CStr(tblPrintLabels.Rows(intLabelCount)("BARCODE_NO")))
.Font = New Font("Code 128", 28)
.AutoSize = True
.Location = New Point(25, 77 + 135 * intLabelCount)
End With
Me.Controls.Add(TempLabel)
however when i try to print this using :
e.Graphics.DrawString(BarcodeConverter128.StringToBarcode(CStr(tblPrintLabels.Rows(intLabelCount)("B ARCODE_NO"))), _
prFont1, Brushes.Black, 25, 77 + LabelsOnPage * 135)
I get a bunch of junk.
is there a way for the print document control to also use the reference that i added?
Are you sure the font is installed? You could use this code to check.
Code:
...
If Not IsFontInstalled("Code 128") Then
Throw New Exception("Code 128 font is not installed.")
End If
...
Private Function IsFontInstalled(ByVal fontName As String) As Boolean
Dim installedFonts As New System.Drawing.Text.InstalledFontCollection
Dim fontFamilies = installedFonts.Families
For Each family In fontFamilies
If fontName.Equals(family.Name, StringComparison.InvariantCultureIgnoreCase) Then
Return True
End If
Next
Return False
End Function
That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma
Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney
If he uses the same font is not very compatible with visual studio. If i try to use it directly at desing time i get an error."The font is not truetype". If you set the font at runtime all runs OK.
Last edited by yo mismo; Dec 1st, 2011 at 11:56 AM.
@Wild_Bill My font has been installed. When I try your code, it doesn't throw the new exception.
@yo_mismo I want to confirm that when you use the code you provided, you can see the barcode instead of the letters IN the PRINT PREVIEW. Because I still letters and not the barcode in print preview. As a label on the form, the barcode is correct
Decided to draw it as an image. since i cant figure out the blasted drawing font problem.
so just made a label, made it an image, and print the sucker
Thank you all for your inputs.
code below if interested:
Code:
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim img As New Bitmap(130, 40)
Dim imgsize As Size
Dim rect As New Rectangle(12, 12, 130, 40)
Dim myFont As New Font("Code 128", 28)
Label1.Text = "Í !È3DÎ"
Label1.Font = myFont
Label1.DrawToBitmap(img, rect) 'problem is here
imgsize = New Size(img.Width, img.Height)
e.Graphics.DrawImage(img, New Rectangle(New Point(12, 12), imgsize))
e.HasMorePages = False
End Sub
Yah wow... that was a while ago...
turned out I was doing it all wrong..
printing barcodes you need to use a dedicated barcode printer. all it will be very hard for scanners to read the barcodes.
These barcode printers use there own script which are in normal text .txt files.
and you control what is printed from the textfiles
if you required some major changes, you just repeatedly yell at the printer supplier over the phone until they come and take you request.