USING IRONBARCODE

How to Print A Barcode Label in VB .NET

Published March 6, 2024
Share:

Barcode labels are crucial in inventory management, product tracking, and supply chain operations. In this article, we will learn barcode printing in VB.NET using IronBarcode. Whether you’re a seasoned developer or just starting, we’ll explore the ways of creating and printing barcode labels efficiently. From designing label templates to handling printer settings, our step-by-step approach will empower you to generate accurate and visually appealing labels for your business needs.

How to Print Barcode Labels in VB.NET

  1. Create or open a project in Visual Studio
  2. Generate the barcode
  3. Resize the barcode
  4. Add a barcode valWue and annotation text
  5. Style the barcode

Why Barcode Labels Matter

Before we dive into the technical details, let’s understand why barcode labels matter:

  1. Efficient Data Representation: Barcodes encode essential information such as product IDs, batch numbers, expiration dates, and pricing. When scanned, they provide instant access to relevant data, streamlining processes across various industries.
  2. Error Reduction: Manual data entry is prone to errors. Barcode labels eliminate the risk of human mistakes, ensuring accurate data capture during inventory management, sales transactions, and shipping.
  3. Supply Chain Optimization: Barcodes facilitate seamless tracking of goods throughout the supply chain. From manufacturers to retailers, everyone benefits from standardized labeling.

Why VB.NET and IronBarcode?

VB.NET is a powerful and versatile programming language, perfect for automating tasks like label printing. But it doesn't have built-in barcode generation capabilities. That's where IronBarcode comes in, a library that provides all the barcode-related functionalities. Integrate it into your project, and you're ready to utilize the barcode power!

IronBarcode

IronBarcode is a powerful .NET library that simplifies barcode generation and manipulation. Whether you’re building inventory management systems, retail applications, or supply chain solutions, IronBarcode provides a seamless way to create, read, and print barcodes. With support for various barcode symbologies (such as Code 39, QR codes, and UPC), customizable settings, and straightforward integration into your VB.NET or C# projects, IronBarcode empowers developers to handle barcode-related tasks efficiently. Its intuitive API allows you to generate accurate and visually appealing barcode labels, enhancing data accuracy and streamlining business processes.

Generating and Printing Barcodes

Now, we will write the code to generate and print barcodes in the VB.NET project. First of all, you need to create or open a VB.NET project. Then you need to install the IronBarcode library. I will be using the Console Application for this project, however, you may use any project type as per your requirements as this code works for all project types.

Installing IronBarcode Library

To seamlessly integrate the IronBarcode library into your project via the Package Manager Console, simply execute the following step-by-step procedure for a smooth installation process:

  1. Open your Visual Studio project.
  2. Click on Tools in the menu.
  3. Select NuGet Package Manager.
  4. Choose Package Manager Console.
  5. In the console, type the following command and press Enter:

    Install-Package BarCode
  6. This command will download and install the IronBarcode package for you.

How to Print A Barcode Label in VB .NET: Figure 1 - Console messages documenting IronBarcode installation

IronBarcode is free for development purposes but requires a license to explore all its functionality.

Generating a Barcode image

Write the following code to generate a Barcode.

Imports IronBarCode
Module Program
  Private Sub Main(args As String())
    ' Creating a barcode is as simple as:
    Dim myBarcode = BarcodeWriter.CreateBarcode("123456BCX65432", BarcodeWriterEncoding.Code128)
    ' And save our barcode as in image:
    myBarcode.SaveAsImage("myBarcode.jpeg")
  End Sub
End Module
Imports IronBarCode
Module Program
  Private Sub Main(args As String())
    ' Creating a barcode is as simple as:
    Dim myBarcode = BarcodeWriter.CreateBarcode("123456BCX65432", BarcodeWriterEncoding.Code128)
    ' And save our barcode as in image:
    myBarcode.SaveAsImage("myBarcode.jpeg")
  End Sub
End Module
VB.NET

The above code simplifies the process of generating a barcode image. It shows how to use the IronBarcode library to create a barcode and save it as an image. It’s like turning a piece of data into a scannable picture! The explanation is as:

  1. The first line, Imports IronBarCode, tells our program to use the features provided by the IronBarcode library. This library helps us create and manipulate barcodes.
  2. The next part of the code creates a barcode. Specifically, it generates a barcode for the value "123456BCX65432" using the Code 128 encoding. Think of a barcode as a unique pattern of lines and spaces that represents information (like a product ID or a serial number).
  3. After creating the barcode, we save it as an image file named "myBarcode.jpeg". This image file will contain the visual representation of the barcode, which can be printed or displayed on screens.

Output

How to Print A Barcode Label in VB .NET: Figure 2 - Outputted barcode from the previous code example

Let's resize our barcode to fit to printable area.

Resizing the Barcode image

The following code will resize our barcode as per the provided dimension.

Private Sub Main(args As String())
     ' Creating a barcode is as simple as:
     Dim myBarcode = BarcodeWriter.CreateBarcode("123456BCX65432", BarcodeWriterEncoding.Code128)
     ' Resize the Barcoce:
     myBarcode.ResizeTo(400, 100)
     ' And save our barcode as in image:
     myBarcode.SaveAsImage("myBarcode.jpeg")
 End Sub
Private Sub Main(args As String())
     ' Creating a barcode is as simple as:
     Dim myBarcode = BarcodeWriter.CreateBarcode("123456BCX65432", BarcodeWriterEncoding.Code128)
     ' Resize the Barcoce:
     myBarcode.ResizeTo(400, 100)
     ' And save our barcode as in image:
     myBarcode.SaveAsImage("myBarcode.jpeg")
 End Sub
VB.NET

The Process of Creating a barcode remains the same. We have just an additional line of code to resize the image before saving. The second line of code resizes the barcode. We adjust its dimensions to be 400 pixels wide and 100 pixels tall. This step ensures that the barcode fits well within the desired space when displayed or printed.

The Output is as:

Output

How to Print A Barcode Label in VB .NET: Figure 3 - The resized barcode image from the previous code

Let's add the Barcode Value and annotation text below or above our barcode.

Adding a Barcode Value and Annotation

The following source code will add a Barcode Value, and Annotation text below and above the barcode respectively.

Private Sub Main(args As String())
     ' Creating a barcode is as simple as:
     Dim myBarcode = BarcodeWriter.CreateBarcode("123456BCX65432", BarcodeWriterEncoding.Code128)
     ' Resize the Barcoce:
     myBarcode.ResizeTo(400, 100)
     myBarcode.AddAnnotationTextAboveBarcode("This is my test barcode generated using Iron Barcode.")
     myBarcode.AddBarcodeValueTextBelowBarcode()
     ' And save our barcode as in image:
     myBarcode.SaveAsImage("myBarcode.jpeg")
 End Sub
Private Sub Main(args As String())
     ' Creating a barcode is as simple as:
     Dim myBarcode = BarcodeWriter.CreateBarcode("123456BCX65432", BarcodeWriterEncoding.Code128)
     ' Resize the Barcoce:
     myBarcode.ResizeTo(400, 100)
     myBarcode.AddAnnotationTextAboveBarcode("This is my test barcode generated using Iron Barcode.")
     myBarcode.AddBarcodeValueTextBelowBarcode()
     ' And save our barcode as in image:
     myBarcode.SaveAsImage("myBarcode.jpeg")
 End Sub
VB.NET

The code for creating, resizing, and saving barcodes remains the same. We have just added two additional lines for adding annotation text and value.

The third line of code adds an annotation (text) above the barcode. The annotation says: “This is my test barcode generated using Iron Barcode.” Annotations provide additional context or information about the barcode.

The fourth line of code adds the actual barcode value below the barcode. For example, if the barcode represents a product ID, this text would display the product ID.

The barcode generated is as:

Output Barcode image

How to Print A Barcode Label in VB .NET: Figure 4 - Annotated barcode with a barcode value

Let's style our barcode by changing the background and barcode color.

Style Barcode

The following code will change the background color and the image color.

myBarcode.ChangeBarCodeColor(IronSoftware.Drawing.Color.DarkBlue)
 myBarcode.ChangeBackgroundColor(IronSoftware.Drawing.Color.Cornsilk)
myBarcode.ChangeBarCodeColor(IronSoftware.Drawing.Color.DarkBlue)
 myBarcode.ChangeBackgroundColor(IronSoftware.Drawing.Color.Cornsilk)
VB.NET

The code for creating barcodes remains the same, We have added additional lines to change the background color and barcode color.

The first line of code modifies the color of the barcode itself. We set the barcode color to Dark Blue using the ChangeBarCodeColor method. This means that the lines and spaces in the barcode will appear in a dark blue hue.

The second line of code adjusts the background color behind the barcode. We set the background color to a light shade called Cornsilk using the ChangeBackgroundColor method. This ensures that the barcode stands out clearly against the background.

The output is as:

Output

How to Print A Barcode Label in VB .NET: Figure 5 - Styled barcode from the previous code

This will generate a barcode image, you can now use the print Dialogue Box of .NET Winforms if you are developing an application for Windows Forms.

Conclusion

In this comprehensive guide, we've explored the essential role of barcode labels in data representation, error reduction, and supply chain optimization. Leveraging the power of VB.NET and the IronBarcode library, developers can seamlessly generate, read, manipulate, and print barcodes. The step-by-step approach covers installation, barcode generation, resizing, annotation addition, and styling, providing a versatile toolkit for creating accurate and visually appealing labels. Whether you're a seasoned developer or just starting, this guide equips you to enhance efficiency in inventory management, sales transactions, and supply chain operations, making barcode integration a valuable asset for business applications.

IronBarcode offers a free trial for extended and production use.

< PREVIOUS
How To Create a Blazor QR Code Scanner
NEXT >
How to use the VB .NET For Barcode Reader Component

Ready to get started? Version: 2024.11 just released

Free NuGet Download Total downloads: 1,290,353 View Licenses >