Link to home
Start Free TrialLog in
Avatar of icarus2256
icarus2256Flag for United States of America

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.IContainer

    '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.TextBox
    Friend WithEvents lblPrevious As System.Windows.Forms.Label
    Friend WithEvents txtPrevious As System.Windows.Forms.TextBox
    Friend WithEvents btnExit As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.txtBarcode = New System.Windows.Forms.TextBox
        Me.lblPrevious = New System.Windows.Forms.Label
        Me.txtPrevious = New System.Windows.Forms.TextBox
        Me.btnExit = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'txtBarcode
        '
        Me.txtBarcode.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.txtBarcode.Font = New System.Drawing.Font("Verdana", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtBarcode.ForeColor = System.Drawing.Color.FromArgb(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("Rockwell", 12.0!, CType((System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Italic), System.Drawing.FontStyle), System.Drawing.GraphicsUnit.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.ContentAlignment.MiddleCenter
        '
        'txtPrevious
        '
        Me.txtPrevious.Font = New System.Drawing.Font("Verdana", 9.75!, CType((System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Italic), System.Drawing.FontStyle), System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtPrevious.ForeColor = System.Drawing.SystemColors.ControlText
        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.FromArgb(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.txtPrevious)
        Me.Controls.Add(Me.lblPrevious)
        Me.Controls.Add(Me.txtBarcode)
        Me.ForeColor = System.Drawing.SystemColors.ControlText
        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.KeyEventArgs) 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.Graphics)

        yPos = 100

        line = newBarcode

        ptr.Graphics.DrawString(line, 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
     
Avatar of cookre
cookre
Flag of United States of America image

Have you not tried it using the printer's own code sequences for bar code printing?

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,“DATA”
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.
Avatar of icarus2256

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
Avatar of cookre
cookre
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial