borderAndreaVB free resources for Visual Basic developersborder

AndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2010 Andrea Tincani

AndreaVB Home | News Home | Forum Home | Downloads | Register | Search | PM | Profile

Previous Topic (Aspose.Newsletter June 2010 Edition is out now)Next Topic (Read Outlook PST File, Extract Messages & Save in MSG Format) New Topic Post Reply
AndreaVB OnLine : News : How to data binding custom objects to print barcode labels with Zebra ZPL printers and VB.NET or C#
Poster Resource
Neodynamic
Level: Master

Registered: 08-12-2005
Posts: 131
icon How to data binding custom objects to print barcode labels with Zebra ZPL printers and VB.NET or C#

How to data binding custom objects to print barcode labels with Zebra ZPL printers and VB.NET or C# by using ThermalLabel SDK for .NET

Prerequisites
- Neodynamic ThermalLabel SDK for .NET
- Microsoft .NET Framework 2.0 (or greater)
- Microsoft Visual Studio 2005 / 2008
- Microsoft Visual Studio 2005 / 2008 Express Editions (VB, C#, J#, and C++)
- Any Zebra Thermal Printer supporting ZPL (Zebra Programming Language)

ThermalLabel SDK supports .NET Data Binding scenarios allowing you to print thermal labels bound to a data source such as custom .NET objects, XML files, Databases, ADO.NET, etc.

In this guide you will learn how to perform data binding with .NET Custom Objects to print barcode labels with Zebra ZPL printers by using ThermalLabel SDK for .NET

The following sample features a class called Product with two basic properties: Id and Name. A list of Product and a ThermalLabel objects will be used to perform data binding scenario printing a set of thermal labels for each product as shown in the following figure.


IMPORTANT: To test the sample code you must have installed a Zebra ZPL thermal printer.

Follow these steps:
- Download and install latest version of Neodynamic ThermalLabel SDK for .NET
- Open Visual Studio 2005 / 2008 and create a Windows Forms application.
- Add a reference to Neodynamic.SDK.ThermalLabel.dll assembly.
- Add a Class file and name it Product. After that paste the following code into it:
  Visual Basic .NET
  Public Class Product
      Dim _id As String
      Dim _name As String

      Public Sub New(ByVal id As String, ByVal name As String)
          Me.Id = id
          Me.Name = name
      End Sub

      Public Property Id() As String
          Get
              Return _id
          End Get
          Set(ByVal value As String)
              _id = value
          End Set
      End Property

      Public Property Name() As String
          Get
              Return _name
          End Get
          Set(ByVal value As String)
              _name = value
          End Set
      End Property
  End Class

  Visual C# .NET
  public class Product
  {
      string _id;
      string _name;
    
      public Product(string id, string name)
      {
          this.Id = id;
          this.Name = name;
      }

      public string Id
      {
          get { return _id; }
          set { _id = value; }
      }

      public string Name
      {
          get { return _name; }
          set { _name = value; }
      }
  }
- Add a Class file and name it Product. After that paste the following code into it:
  Visual Basic .NET
  'Define a ThermalLabel object and set unit to cm and label size
  Dim tLabel As New ThermalLabel(UnitType.Cm, 6, 4)

  'Define a TableShapeItem object
  Dim table As New TableShapeItem(0.5, 0.5, 5, 3, 1, 2)
  'Set stroke thickness
  table.StrokeThickness = 0.05

  'Set first row height
  table.Rows(0).Height = 0.75

  'First Cell settings...
  table.Cells(0, 0).Padding.Top = 0.2
  table.Cells(0, 0).Content = CellContent.Text
  'Set Data Source field...
  table.Cells(0, 0).ContentText.DataField = "Name"
  table.Cells(0, 0).ContentText.TextAlignment = TextAlignment.Center
  table.Cells(0, 0).ContentText.Font.Name = "0"
  table.Cells(0, 0).ContentText.Font.CharHeight = 12
  'Second Cell settings...
  table.Cells(1, 0).Padding.Top = 0.2
  table.Cells(1, 0).Padding.Left = 0.75
  table.Cells(1, 0).Content = CellContent.Barcode
  table.Cells(1, 0).ContentBarcode.Symbology = BarcodeSymbology.Code128
  'Set Data Source field...
  table.Cells(1, 0).ContentBarcode.DataField = "Id"
  table.Cells(1, 0).ContentBarcode.BarWidth = 0.04
  table.Cells(1, 0).ContentBarcode.BarHeight = 1.25

  'Add items to ThermalLabel object...
  tLabel.Items.Add(table)

  'Create data source...
  Dim products As New List(Of Product)
  products.Add(New Product("OO2935", "Olive Oil"))
  products.Add(New Product("CS4948", "Curry Sauce"))
  products.Add(New Product("CH0094", "Chocolate"))
  products.Add(New Product("MZ1027", "Mozzarella"))

  'set data source...
  tLabel.DataSource = products

  'Create a PrintJob object
  Dim pj As New PrintJob()
  'Thermal Printer is connected through USB
  pj.PrinterSettings.Communication.CommunicationType = CommunicationType.USB
  'Set Thermal Printer resolution
  pj.PrinterSettings.Dpi = 203
  'Set Thermal Printer name
  pj.PrinterSettings.PrinterName = "Zebra  TLP2844-Z"
  'Print ThermalLabel object...
  pj.Print(tLabel)

  Visual C# .NET
  //Define a ThermalLabel object and set unit to cm and label size
  ThermalLabel tLabel = new ThermalLabel(UnitType.Cm, 6, 4);

  //Define a TableShapeItem object
  TableShapeItem table = new TableShapeItem(0.5, 0.5, 5, 3, 1, 2);
  //Set stroke thickness
  table.StrokeThickness = 0.05;

  //Set first row height
  table.Rows[0].Height = 0.75;

  //First Cell settings...
  table.Cells[0, 0].Padding.Top = 0.2;
  table.Cells[0, 0].Content = CellContent.Text;
  //Set Data Source field...
  table.Cells[0, 0].ContentText.DataField = "Name";
  table.Cells[0, 0].ContentText.TextAlignment = TextAlignment.Center;
  table.Cells[0, 0].ContentText.Font.Name = "0";
  table.Cells[0, 0].ContentText.Font.CharHeight = 12;
  //Second Cell settings...
  table.Cells[1, 0].Padding.Top = 0.2;
  table.Cells[1, 0].Padding.Left = 0.75;
  table.Cells[1, 0].Content = CellContent.Barcode;
  table.Cells[1, 0].ContentBarcode.Symbology = BarcodeSymbology.Code128;
  //Set Data Source field...
  table.Cells[1, 0].ContentBarcode.DataField = "Id";
  table.Cells[1, 0].ContentBarcode.BarWidth = 0.04;
  table.Cells[1, 0].ContentBarcode.BarHeight = 1.25;

  //Add items to ThermalLabel object...
  tLabel.Items.Add(table);

  //Create data source...
  List<Product> products = new List<Product>();
  products.Add(new Product("OO2935", "Olive Oil"));
  products.Add(new Product("CS4948", "Curry Sauce"));
  products.Add(new Product("CH0094", "Chocolate"));
  products.Add(new Product("MZ1027", "Mozzarella"));

  //set data source...
  tLabel.DataSource = products;

  //Create a PrintJob object
  PrintJob pj = new PrintJob();
  //Thermal Printer is connected through USB
  pj.PrinterSettings.Communication.CommunicationType = CommunicationType.USB;
  //Set Thermal Printer resolution
  pj.PrinterSettings.Dpi = 203;
  //Set Thermal Printer name
  pj.PrinterSettings.PrinterName = "Zebra  TLP2844-Z";
  //Print ThermalLabel object...
  pj.Print(tLabel);

- Run the sample Windows Forms application and test it.

Links:
This Demo
More Demos
Download ThermalLabel SDK for .NET
More Information about Neodynamic ThermalLabel SDK for .NET


Neodynamic
.NET Components & Controls
http://www.neodynamic.com

05-01-2009 at 04:55 PM
View Profile Send Email to User Show All Posts Visit Homepage | Add Comment
gonzo
Level: Trainee

Registered: 01-06-2010
Posts: 1
icon Re: How to data binding custom objects to print barcode labels with Zebra ZPL printers and VB.NET or C#

Great bit of info, I have found it very informative. It has helped me a lot in the producing of my own custom barcode labels.

Thanks again

[Edited by gonzo on 01-06-2010 at 11:07 AM GMT]

01-06-2010 at 11:07 AM
View Profile Send Email to User Show All Posts | Add Comment
AndreaVB OnLine : News : How to data binding custom objects to print barcode labels with Zebra ZPL printers and VB.NET or C#
Previous Topic (Aspose.Newsletter June 2010 Edition is out now)Next Topic (Read Outlook PST File, Extract Messages & Save in MSG Format)New Topic Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2010 Andrea Tincaniborder