icarus2256
asked on
code 39 Barcode not printing out of vb.net correctly????
We have returns employees who scan in specific barcodes and need other barcodes printed back out to them. I am programming the export of the new barcodes that they will place on the return boxes. I am having however problems formatting the barcode to sit well on a 2.25X2.5 label. We are using a Zebra LP 2844 printer for the printing of the labels. I haven't messed around much with printer objects in vb.net so I am fairly new to the whole thing. Are there settings in my code that I should change to make the barcode fit?? Here is a sample barcode number: 6103766213SUNDT004425103. I need that number to print out in the form of a barcode on the 2.25X2.5 label, but I am having all types of problems with the formatting. Can someone please help me. You guys are the best. Here is my code:
Imports System.Drawing.Printing
Imports System.Drawing.Text
Public Class Form1
Inherits System.Windows.Forms.Form
Public ptrFont As Font
Public strBarcode As String
Public newBarcode As String
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon tainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents txtBarcode As System.Windows.Forms.TextB ox
Friend WithEvents lblPrevious As System.Windows.Forms.Label
Friend WithEvents txtPrevious As System.Windows.Forms.TextB ox
Friend WithEvents btnExit As System.Windows.Forms.Butto n
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
Me.txtBarcode = New System.Windows.Forms.TextB ox
Me.lblPrevious = New System.Windows.Forms.Label
Me.txtPrevious = New System.Windows.Forms.TextB ox
Me.btnExit = New System.Windows.Forms.Butto n
Me.SuspendLayout()
'
'txtBarcode
'
Me.txtBarcode.CharacterCas ing = System.Windows.Forms.Chara cterCasing .Upper
Me.txtBarcode.Font = New System.Drawing.Font("Verda na", 12.0!, System.Drawing.FontStyle.B old, System.Drawing.GraphicsUni t.Point, CType(0, Byte))
Me.txtBarcode.ForeColor = System.Drawing.Color.FromA rgb(CType( 255, Byte), CType(128, Byte), CType(0, Byte))
Me.txtBarcode.Location = New System.Drawing.Point(96, 32)
Me.txtBarcode.MaxLength = 100
Me.txtBarcode.Name = "txtBarcode"
Me.txtBarcode.Size = New System.Drawing.Size(400, 27)
Me.txtBarcode.TabIndex = 0
Me.txtBarcode.Text = ""
'
'lblPrevious
'
Me.lblPrevious.Font = New System.Drawing.Font("Rockw ell", 12.0!, CType((System.Drawing.Font Style.Bold Or System.Drawing.FontStyle.I talic), System.Drawing.FontStyle), System.Drawing.GraphicsUni t.Point, CType(0, Byte))
Me.lblPrevious.ForeColor = System.Drawing.Color.Red
Me.lblPrevious.Location = New System.Drawing.Point(56, 152)
Me.lblPrevious.Name = "lblPrevious"
Me.lblPrevious.Size = New System.Drawing.Size(160, 32)
Me.lblPrevious.TabIndex = 1
Me.lblPrevious.Text = "Previous Serial #:"
Me.lblPrevious.TextAlign = System.Drawing.ContentAlig nment.Midd leCenter
'
'txtPrevious
'
Me.txtPrevious.Font = New System.Drawing.Font("Verda na", 9.75!, CType((System.Drawing.Font Style.Bold Or System.Drawing.FontStyle.I talic), System.Drawing.FontStyle), System.Drawing.GraphicsUni t.Point, CType(0, Byte))
Me.txtPrevious.ForeColor = System.Drawing.SystemColor s.ControlT ext
Me.txtPrevious.Location = New System.Drawing.Point(224, 160)
Me.txtPrevious.MaxLength = 100
Me.txtPrevious.Name = "txtPrevious"
Me.txtPrevious.ReadOnly = True
Me.txtPrevious.Size = New System.Drawing.Size(272, 23)
Me.txtPrevious.TabIndex = 2
Me.txtPrevious.Text = ""
'
'btnExit
'
Me.btnExit.Location = New System.Drawing.Point(512, 208)
Me.btnExit.Name = "btnExit"
Me.btnExit.TabIndex = 3
Me.btnExit.Text = "Exit"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.Color.FromA rgb(CType( 192, Byte), CType(192, Byte), CType(255, Byte))
Me.ClientSize = New System.Drawing.Size(600, 238)
Me.Controls.Add(Me.btnExit )
Me.Controls.Add(Me.txtPrev ious)
Me.Controls.Add(Me.lblPrev ious)
Me.Controls.Add(Me.txtBarc ode)
Me.ForeColor = System.Drawing.SystemColor s.ControlT ext
Me.Name = "Form1"
Me.Text = "Newgistics Barcode Application"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub txtBarcode_KeyDown(ByVal sender As Object, ByVal keyPress As System.Windows.Forms.KeyEv entArgs) Handles txtBarcode.KeyDown
If keyPress.KeyValue = Keys.Enter Then
Dim ptrLabel As New PrintDocument
strBarcode = txtBarcode.Text
txtPrevious.Text = strBarcode
ptrFont = New Font("IDAutomationHC39M", 12)
newBarcode = "*" & strBarcode & "*"
AddHandler ptrLabel.PrintPage, AddressOf Me.ptrLabel_PrintPage
ptrLabel.Print()
txtBarcode.Clear()
End If
End Sub
Private Sub ptrLabel_PrintPage(ByVal sender As Object, ByVal ptr As PrintPageEventArgs)
Dim linesPerPage As Single = 0
Dim yPos As Single = 0
Dim leftMargin As Single = ptr.MarginBounds.Left
Dim topMargin As Single = ptr.MarginBounds.Top
Dim line As String = Nothing
linesPerPage = ptr.MarginBounds.Height / ptrFont.GetHeight(ptr.Grap hics)
yPos = 100
line = newBarcode
ptr.Graphics.DrawString(li ne, ptrFont, Brushes.Black, leftMargin, yPos, New StringFormat)
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
Imports System.Drawing.Printing
Imports System.Drawing.Text
Public Class Form1
Inherits System.Windows.Forms.Form
Public ptrFont As Font
Public strBarcode As String
Public newBarcode As String
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents txtBarcode As System.Windows.Forms.TextB
Friend WithEvents lblPrevious As System.Windows.Forms.Label
Friend WithEvents txtPrevious As System.Windows.Forms.TextB
Friend WithEvents btnExit As System.Windows.Forms.Butto
<System.Diagnostics.Debugg
Me.txtBarcode = New System.Windows.Forms.TextB
Me.lblPrevious = New System.Windows.Forms.Label
Me.txtPrevious = New System.Windows.Forms.TextB
Me.btnExit = New System.Windows.Forms.Butto
Me.SuspendLayout()
'
'txtBarcode
'
Me.txtBarcode.CharacterCas
Me.txtBarcode.Font = New System.Drawing.Font("Verda
Me.txtBarcode.ForeColor = System.Drawing.Color.FromA
Me.txtBarcode.Location = New System.Drawing.Point(96, 32)
Me.txtBarcode.MaxLength = 100
Me.txtBarcode.Name = "txtBarcode"
Me.txtBarcode.Size = New System.Drawing.Size(400, 27)
Me.txtBarcode.TabIndex = 0
Me.txtBarcode.Text = ""
'
'lblPrevious
'
Me.lblPrevious.Font = New System.Drawing.Font("Rockw
Me.lblPrevious.ForeColor = System.Drawing.Color.Red
Me.lblPrevious.Location = New System.Drawing.Point(56, 152)
Me.lblPrevious.Name = "lblPrevious"
Me.lblPrevious.Size = New System.Drawing.Size(160, 32)
Me.lblPrevious.TabIndex = 1
Me.lblPrevious.Text = "Previous Serial #:"
Me.lblPrevious.TextAlign = System.Drawing.ContentAlig
'
'txtPrevious
'
Me.txtPrevious.Font = New System.Drawing.Font("Verda
Me.txtPrevious.ForeColor = System.Drawing.SystemColor
Me.txtPrevious.Location = New System.Drawing.Point(224, 160)
Me.txtPrevious.MaxLength = 100
Me.txtPrevious.Name = "txtPrevious"
Me.txtPrevious.ReadOnly = True
Me.txtPrevious.Size = New System.Drawing.Size(272, 23)
Me.txtPrevious.TabIndex = 2
Me.txtPrevious.Text = ""
'
'btnExit
'
Me.btnExit.Location = New System.Drawing.Point(512, 208)
Me.btnExit.Name = "btnExit"
Me.btnExit.TabIndex = 3
Me.btnExit.Text = "Exit"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.Color.FromA
Me.ClientSize = New System.Drawing.Size(600, 238)
Me.Controls.Add(Me.btnExit
Me.Controls.Add(Me.txtPrev
Me.Controls.Add(Me.lblPrev
Me.Controls.Add(Me.txtBarc
Me.ForeColor = System.Drawing.SystemColor
Me.Name = "Form1"
Me.Text = "Newgistics Barcode Application"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub txtBarcode_KeyDown(ByVal sender As Object, ByVal keyPress As System.Windows.Forms.KeyEv
If keyPress.KeyValue = Keys.Enter Then
Dim ptrLabel As New PrintDocument
strBarcode = txtBarcode.Text
txtPrevious.Text = strBarcode
ptrFont = New Font("IDAutomationHC39M", 12)
newBarcode = "*" & strBarcode & "*"
AddHandler ptrLabel.PrintPage, AddressOf Me.ptrLabel_PrintPage
ptrLabel.Print()
txtBarcode.Clear()
End If
End Sub
Private Sub ptrLabel_PrintPage(ByVal sender As Object, ByVal ptr As PrintPageEventArgs)
Dim linesPerPage As Single = 0
Dim yPos As Single = 0
Dim leftMargin As Single = ptr.MarginBounds.Left
Dim topMargin As Single = ptr.MarginBounds.Top
Dim line As String = Nothing
linesPerPage = ptr.MarginBounds.Height / ptrFont.GetHeight(ptr.Grap
yPos = 100
line = newBarcode
ptr.Graphics.DrawString(li
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
ASKER
I am a little confused with the printers own code sequence you suggested using. Is this something that I must code in vb.net or something like textpad and send it to the printer?? Can't I configure print properties inside .net?? If not just help me through the printers code sequence you listed above. Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Get the EPL2 manual here:
http://www.zebra.com/SS/manuals.htm
Look at the B command:
Syntax Bp1,p2,p3,p4,p5,p6,p7,p8,“
p1 = Horizontal start position (X) in dots
p2 = Ver ti cal start po si tion (Y) in dots
p3 = Rotation
0 No rotation
1 90 degrees
2 180 degrees
3 270 degrees
p4 = Bar Code selection (see Table 2-1)
p5 = Narrowbar width in dots. (see Ta ble 2-1).
p6 = Wide bar width in dots.
p7 = Bar code height in dots.
p8 = Print human readable code.
B=yes or N=no.