Solved

code 39 Barcode not printing out of vb.net correctly????

Posted on 2004-09-27
3
1,019 Views
Last Modified: 2011-10-03
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
     
0
Comment
Question by:icarus2256
  • 2
3 Comments
 
LVL 22

Expert Comment

by:cookre
Comment Utility
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.
0
 

Author Comment

by:icarus2256
Comment Utility
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
0
 
LVL 22

Accepted Solution

by:
cookre earned 250 total points
Comment Utility
I don't have one of those printers to test on, I'm just reading the above linked to manual, but it would appear that, as long as the printer is in AutoSense mode, you can sen EPL2 commands directly to the printer.  For example, sending the string:

B2,3,1,3,4,7,50,B,"123456-789"

will display the Code 39 barcode for 123456-789 according to the parameters:


p1=2 - horizontal dot position 2
p2=3 - vertical dot position 3
p3=1 - rotate 90 degrees
p4=3 - use Code 39
p5=4 - narrow bar width 4
p6=7 - wide bar width 7
p7=50 - bar height 50
p8=B - display human readable code


You'll have to fiddle with the various parameters to get it to fit on the stock you're using.


Also, take a look at:
http://forums.devshed.com/showthread.php?p=712926
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
dividesSelf challange 15 76
wordsWithout 49 77
mapAB Challlenge 35 84
Counting documents in a Domino View 3 31
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now