Home > .NET Barcode > VB.NET Barcode Generation Guide > VB.NET QR-Code Generator for .NET WinForms, ASP.NET

VB.NET QR Code Barcode Generator Library


How to Create QR-Code Barcodes in .NET applications with Visual Basic/VB.NET
  • Mature VB.NET Barcode Generator component for high-quality QR Code barcode generation
  • Developed completely in Visual C#, with full integration into .NET Framework
  • Create QR Code images in ASP.NET web application and windows application using VB.NET
  • Print, embed QR Codes in Crystal Reports, SSRS Reporting Services and RDLC Local Reports
  • QR-Code barcodes generated are readable & compatible with the latest specification
  • Multiple QR Code barcode settings are adjustable with simple VB.NET programming
  • Simple to control QR Code image size and shape via Properties Window in VB.NET project
  • Offer cost-effective developer license for commercial application development


VB.NET 2D QR Code Barcode Introduction

QR-Code, also known as Quick Response Code, Denso Barcode, QRCode, JIS X 0510, ISO/IEC 18004, is a matrix (two-dimensional symbol) symbology initially designed by Denso Wave for the automotive industry. And now it is widely used in various industries for its fast readability and data capacity.

Compatibility: Barcode for .NET component SDK is compatible with ISO/IEC 18004 (Second Edition 2006-09-01) bar code symbology specification.
Encoding: QR-Code bar code can encode multiple types of data, including numeric and alphanumeric characters (A-Z, a-z, 0-9), Kanji characters (JIS X 0510), and byte data (default is ISO/IEC 8859-1, including characters from English, German, French, Italian, Spanish, Portuguese, Dutch, Afrikaans, etc.)
To get more information on QR Code bar code, please refer to .NET QR-Code Introduction


Quick to Create and Print QR Code in VB.NET Class

Generating and printing a QR Code in a Visual Basic class using the BarcodeLib VB.NET Barcode Generator library requires only a few steps.

The following steps illustrate how to generate a QR Code using the BarcodeLib VB.NET Barcode Generator library.

  1. Create a QRCode object in your VB.NET code.
  2. Assign the data to be encoded to the Data property. For example, you might enter a website URL or a product identifier.
  3. Call the drawBarcode() method to output the QR Code image. By default, the QR Code is rendered as a PNG image file.

Dim qrcode = New QRCode()
qrcode.Data = "https://www.barcodelib.com"
qrcode.drawBarcode("C://Output//vb-net-qr-code-how-to-demo.png")




Encoding QR Code Complex Data Formats using VB.NET

This section covers how to encode QR Code with specific data types such as full ASCII characters, Unicode text, GS1 messages, and binary data.


Encode QR Code with ASCII characters (including non printing characters)

The full ASCII table consists of 128 characters: 95 printable and 33 control (non printing) characters.

For printable characters: Enter them directly in the Data property.

For non printing characters: Convert each character to its three digit ASCII value, prefixed with a tilde (~).

For example, the carriage return character (ASCII 13) becomes ~013.
  1. Set ProcessTilde to True.
  2. In the Data property, replace each non printing character with its ~ + three digit representation.
Dim qrcode = New QRCode()
qrcode.Data = "ABC~013abc"
qrcode.ProcessTilde = True
qrcode.drawBarcode("C://Output//vb-net-qr-code-how-to-data-ascii.png")




Encode QR Code with Unicode text

To include characters such as accented letters or non Latin scripts, enable Unicode encoding.
  1. Set property IsUnicodeData to True.
  2. Enter the Unicode text directly in the Data property.
Dim qrcode = New QRCode()
qrcode.Data = "你好"
qrcode.IsUnicodeData = True
qrcode.drawBarcode("C://Output//vb-net-qr-code-how-to-data-unicode-text.png")




Create GS1 QR Code

GS1 QR Codes are used in supply chain and retail applications. They incorporate Application Identifiers (AIs) to define the meaning of the encoded data.
  1. Set the FNC1Mode property to QRCodeFNC1Mode.FirstPosition. This inserts a special Function 1 Character at the first position, indicating the QR Code is GS1 compliant.
  2. Enter the GS1 data message in the Data property, enclosing each AI code in parentheses.
Dim qrcode = New QRCode()
qrcode.Data = "(17)050101(10)ABC123"
qrcode.FNC1Mode = QRCodeFNC1Mode.FirstPosition
qrcode.drawBarcode("C://Output//vb-net-qr-code-how-to-data-gs1.png")




Encode QR Code with binary data

Binary data (e.g., images or encrypted content) can be encoded by converting each byte to its three digit integer value with a tilde (~) prefix.
  1. Set ProcessTilde to True.
  2. Convert each byte in the binary data to a string in the format ~xxx, where xxx is the zero padded byte value.
  3. Set property Encoding (QR Code data encoding mode) to QRCodeEncoding.Byte.
Dim message = "你好-hello-in-Chinese"
Dim bytes = Encoding.UTF8.GetBytes(message)
Dim bytesInSb = New StringBuilder()
For Each b In bytes
   bytesInSb.Append("~" + b.ToString().PadLeft(3, "0"))
Next

Dim qrcode = New QRCode()
qrcode.Data = bytesInSb.ToString()
qrcode.ProcessTilde = True
qrcode.Encoding = QRCodeEncoding.Byte
qrcode.drawBarcode("C://Output//vb-net-qr-code-how-to-data-binary.png")


Customize QR Code Dimensions

Setting image width and height

By default, the QR Code image is square. You can adjust its size using the ImageWidth property. The height is automatically set to match the width.

Dim qrcode = New QRCode()
qrcode.Data = "https://www.barcodelib.com"
qrcode.ImageWidth = 250
qrcode.drawBarcode("C://Output//vb-net-qr-code-how-to-size-width-demo.png")




Customizing the module width (X dimension)

The module width (X) controls the size of each individual black or white square in the QR Code. To set it manually, disable automatic resizing.
  1. Set ResizeImage to False.
  2. Specify QR Code image width and height through property ImageWidth and ImageHeight.
  3. Set the desired module width using the ModuleSize property.
Dim qrcode = New QRCode()
qrcode.Data = "https://www.barcodelib.com"
qrcode.ResizeImage = False
qrcode.ImageWidth = 250
qrcode.ImageHeight = 250
qrcode.ModuleSize = 8
qrcode.drawBarcode("C://Output//vb-net-qr-code-how-to-size-module-x-demo.png")


Selecting a QR Code version

QR Code versions (1 to 40) define the size of the symbol. The library automatically selects the appropriate version based on data and error correction settings. You can also specify a version manually.

Dim qrcode = New QRCode()
qrcode.Data = "https://www.barcodelib.com"
qrcode.ImageWidth = 250
qrcode.Version = QRCodeVersion.V5
qrcode.drawBarcode("C://Output//vb-net-qr-code-how-to-qrcode-version.png")


Adjusting quiet zones (margins)

The quiet zone is the blank area surrounding the QR Code. It is essential for reliable scanning. You can customize the margins using the LeftMargin, RightMargin, TopMargin, and BottomMargin properties.

Dim qrcode = New QRCode()
qrcode.Data = "https://www.barcodelib.com"
qrcode.ImageWidth = 250
qrcode.LeftMargin = 30
qrcode.RightMargin = 30
qrcode.TopMargin = 30
qrcode.BottomMargin = 30
qrcode.drawBarcode("C://Output//vb-net-qr-code-how-to-quiet-zones.png")




Customizing QR Code Appearance

Color and image format settings

The BarcodeLib library allows you to change the bar and space colors, as well as the output image format. This is particularly useful when integrating QR Codes into branded WinForms or WPF user interfaces.

You can customize QR Code module and space colors through property ModuleColor and BackgroundColor.

Dim qrcode = New QRCode()
qrcode.Data = "https://www.barcodelib.com"
qrcode.ModuleColor = Color.Red
qrcode.BackgroundColor = Color.White
qrcode.drawBarcode("C://Output//vb-net-qr-code-how-to-color-image.png")




Adding a logo image

You can embed a logo (such as a company logo photo) into the center of the QR Code. This is commonly used for branding in desktop applications.
  1. Set property LogoImage to a Bitmap object with a logo image loaded.
  2. Set property LogoRenderSize to specify the logo image render area size.
  3. Set property RemoveModulesUnderLogoImage to true to remove all QR Code modules covered by the logo image.
  4. Set property ECL to specify the QR Code error correction level.
Dim qrcode = New QRCode()
qrcode.Data = "https://www.facebook.com"
qrcode.ModuleColor = Color.SteelBlue
qrcode.LogoImage = New Bitmap("C://BarcodeLib//facebook.png")
qrcode.LogoRenderSize = New SizeF(90, 90)
qrcode.RemoveModulesUnderLogoImage = True
qrcode.ECL = QRCodeErrorCorrectionLevel.M
qrcode.drawBarcode("C://Output//vb-net-qr-code-how-to-logo.png")




Understanding QR Code Data Encoding

Supported character sets

QR Code can encode several types of data in VB.NET code, each suited for different use cases:
  • Numbers (digits 0 - 9): Ideal for numeric identifiers like product codes.
  • ASCII characters: Includes the standard 128 ASCII characters and extended ASCII.
  • Unicode text: Supports international characters, such as accented letters or non Latin scripts.
  • Binary data: Allows encoding of raw byte data.
  • Kanji characters: Japanese characters that can be compacted into 13 bits for efficiency.


Data modes

The library selects the most efficient encoding mode automatically. You may also specify a mode manually.

Available QRCodeEncoding options:
  • Auto: The library determines the appropriate mode(s) based on the input data. (Recommended for most scenarios)
  • Numeric: For digits only (0 - 9).
  • AlphaNumeric: For uppercase letters, digits, and nine special characters: space, $, %, *, +, -, ., /, :.
  • Byte: For binary or ISO/IEC 8859 1 data.
  • Kanji: For Kanji character encoding.

Sample VB.NET code to specify the QR Code data mode.

barcode.Encoding = QRCodeEncoding.Auto


Maximum data capacity

The maximum number of characters a QR Code can hold depends on the version (up to Version 40) and error correction level.

With the lowest error correction (L):
  • Numeric data: 7,089 characters
  • Alphanumeric data: 4,296 characters
  • Byte data: 2,953 characters
  • Kanji data: 1,817 characters


Error correction level (ECL)

QR Code includes Reed Solomon error correction, which allows data recovery even if part of the symbol is damaged.

Four levels are defined (L, M, Q, H), with increasing correction capacity:
  • L: 7% recovery (default)
  • M: 15% recovery
  • Q: 25% recovery
  • H: 30% recovery
Sample VB.NET source code:

qrcode.ECL = QRCodeErrorCorrectionLevel.M
How to Generate QR Code 2D Bar Code Using VB.NET Class

How to Install

  1. Add barcode dll component to your VB.NET project reference.
    • Click "Project" and select "Add Reference...".
    • Click "Browse" to find Barcodelib.Barcode.ASP.NET.dll or BarcodeLib.Barcode.WinForms.dll in the unzipped file, and click "OK" button.
  2. Add BarcodeLib barcoding dlls to Visual Studio Toolbox.
    • Right click in Toolbox and select "Choose Items...".
    • In the pop-up "Choose Toolbox items" window, click "Browse..." to select either BarcodeLib.Barcode.WinFroms.dll or Barcodelib.Barcode.ASP.NET.dll.
    • Click "OK" and now four items are listed in VS Toolbox, for example: QRCodeWinForm, DataMatrixWinForm, LinearWinForm, and PDF417WinForm.

How to Create QR-Code Bar Codes in VB.NET ASP.NET Web Applications?
BarcodeLib.com QR Code VB.NET generator supports streaming QR Code barcode images in ASP.NET web in two ways.
  1. VB.NET QR Code barcode generation through BarcodeLib Buildin ASP.NET Barcode Application.
    • Unzip the downloaded evaluation package, and copy barcode folder and its contents to your IIS folder, eg. C:\inetpub.
    • Create a new virtual directory in your IIS, name it "barcode", and connect it to the above "barcode" folder in inetpub.
    • Restart IIS for a QR Code streaming test. Simply navigate to:
      http://YourDomain:Port/barcode/qrcode.aspx?Data=12345678&LeftMargin=6&RightMargin=6&TopMargin=6&BottomMargin=6

      Above is the generated QR Code barcode image. If you need to adjust other QR Code dimensions, please view more web stream URL parameters for QR Code here: .NET QR-Code Generator Property Settings.
    • You can also insert this QR Code image in your aspx or html page, simply pass the url to IMG tag or src value.
      For example:
      <img src=http://YourDomain:port/barcode/qrcode.aspx?Data=12345678&LeftMargin=12&RightMargin=12&TopMargin=12&BottomMargin=12 />
      This method will not generate any barcode images in your IIS server side.
  2. VB.NET QR Code barcodes encoding through ASP.NET Web Form Controller.
    • Intall ASP.NET barcode controller to your barcoding project by adding reference.
    • Add barcode library to your Visual Studio toolbox.
    • Open barcode in your unzipped trial package, and copy files "qrcode.aspx", "qrcode.aspx.cs" to the aspx page where you will be generating QR Code images.
    • Now you can drag QRCodeASPNET to your ASP.NET web site, and change QR code settings through properties window on the right.

    • Run the project and a QR Code barcode is generated on your aspx pages.
    • Or you may directly generate QR Code barcodes using above Free demo VB.NET code for your ASP.NET applications.




How to Draw QR-Code Images in VB.NET Windows Applications?
BarcodeLib provides step-by-step tutorial guide to print QR Code on Windows Forms. Learn details here:
How to create, print QR Code and barcodes on Windows Forms application?






Summary

This guide has walked through the essential aspects of generating QR Codes using the BarcodeLib SDK in VB.NET. The library supports a wide range of data types, flexible dimension controls, and customizable appearance options, making it suitable for integration into Windows Forms (WinForms) and Windows Presentation Foundation (WPF) applications. By following the steps and examples provided, you can incorporate QR Code generation into your .NET projects with confidence.