How to generate, print barcode image in C# WPF, Windows Application
How to generate, print barcode image label for Windows Application, WPF with free C# barcode example source code
It works well throughout my whole project. And barcoding features are easy to be implemented with the help of guide documents.
- Kevin Cox, US
Generate and Draw Linear & 2D Barcodes with best Windows Forms C# barcoding application
- Integrate advanced bar code labels generation functions into a single .NET WinForms DLL
- Written in C#, fully compatible with Visual Studio .NET Windows Forms programs
- Simple to generate & encode barcode images on windows form and WPF with free Visual C# example code
- Able to use C# code to generate GS1 compatible barcodes, including
GS1 DataBar,
GS1-128,
ITF-14,
Data Matrix,
QR Code, etc
- Using C# class command to save generated bar code pictures in the memory or in image file format
- All encoded linear & 2d barcode images can be read by high resolution printer or thermal printer
- C# source code available with purchase of Developer License
.NET Barcode Generator SDK is designed for C#.NET barcode generation projects. It can be adapted to generate & display high-quality barcodes for .NET Windows Forms, C# Class Library, and Console applications. It offers free trial download and user-friendly interface. In addition, this professional barcode component also can be used in SQL Server Reporting Services and Client RDLC Reports for barcode printing.
Below are some more tutorials for printing barcodes symbols in VB.NET, such as ASP.NET Web Applications, etc.
- C# Barcode Generation - Samples for programmatically generating barcode images using Visual C# in .NET Framework
- C# Barcode ASP.NET - Samples for dynamically streaming barcodes in C# ASP.NET web applications / web sites
- C# Barcode Imaging - Samples for creating multiple barcodes and adjust bar code image settings with C# code system
- C# Barcode Data - Samples for generating GS1 barcode or encode Unicode (text or numbers) in barcode in C# projects
Besize WinForms for .NET Core app, you can also easily generate barcodes in other desktop applications.
How to Encode & Draw Barcode Label Using C# Source Code

Top
Below are the steps for printing barcodes in C# Class with basic settings. For more barcoding properties or methods, such as alphanumeric string /character encoding, barcode size controlling through width and height, image color, file format of Png / Jpg / Gif / Bitmap, automatic check digit implementation for linear barcode, please go to C# guide page for reference.
- Add .NET WinForms Barcode Library DLL to your Windows C# project reference.
- Use OnBarcode.Barcode as the namespace and copy the following C# demo code your C#.NET class panel. Let's take Data Matrix as an example.
// Create a .NET WinForms Data Matrix object
DataMatrix datamatrix = new DataMatrix();
// Set Data Matrix encoded data
datamatrix.Data = ".NET WinForms C# Data Matrix";
// Set Data Matrix data mode
datamatrix.DataMode = DataMatrixDataMode.Auto;
// Set Data Matrix barcode image size
datamatrix.X = 3;
datamatrix.LeftMargin = 6;
datamatrix.RightMargin = 6;
datamatrix.TopMargin = 6;
datamatrix.BottomMargin = 6;
// Print Data Matrix to gif image file and save it to C:\
datamatrix.ImageFormat = System.Drawing.Imaging.ImageFormat.Gif;
datamatrix.drawBarcode("C://winfroms-csharp-datamatrix.gif");
C#.NET Barcode Generation Tutorials for Supported Barcodes

Top
Barcode SDK for C#.NET - Barcode Image Generation
How to encode, generate non-printable chars (such as 'CR') in barcode images using c# .net winforms

Top
Some barcodes, such as Code 128, QR Code supports non-printable chars encoding. Here is an example to encode char 'CR' (Carriage Return).
- Set property ProcessTilde to true.
- Convert non-printable char to '~ddd' format. Here ddd is the char ASCII Integer code. 'CR' should be converted to '~013'.
- Set property Data to '~013'
How to encode, print GS1 data in barcodes using c# .net winforms

Top
The GS1 system originated in the United States and was established in 1973 by the Uniform Product Code Council, known until recently as the Uniform Code Council, Inc. (UCC) and since 2005 as GS1 US.
The following barcode symbologes support GS1 data encoding:
- EAN/UPC:
UPC-A,
UPC-E,
EAN-13, and
EAN-8 barcodes, and the two- and five-digit add-on symbols
- ITF-14
- GS1-128 (EAN-128)
- GS1 DataBar
- Composite Component symbols do not exist in isolation. The primary identification number is always encoded in the linear symbol and supplementary GS1 Application Identifier element strings are encoded in the two-dimensional (2D) component where they take up less space
- Data Matrix
- GS1 QR Code
Please read each barcode symbology guide page to encode GS1 data.
How to encode, print non-English chars (such as Thai, Korean) in barcode images using c# .net winforms

Top
Most of the barcode types do not support encoding non-English text (such as Thai, Korean) directly. To encode those chars, you need convert non-English chars into byte array, and encode
byte array into barcode.
2D barcodes
Data Matrix,
PDF-417,
QR Code support byte array data mode. Check each barcode symbology guide page to encode non-English chars.
Prerequisites

Top
Download and install the following software on your computer
- Visual Studio 2022
- .NET 6.0 SDK
- OnBarcode.Barcode.Common.dll
Tutorial: Create a new WinForm .NET Core app with barcode generator enabled using C#

Top
1. Create new WinForms Core desktop app
Start Visual Studio 2022 and select "Create a new project".
Select "Windows Forms App" in the dialog, and then press "Next" button.
Create a new project with name "
OnBarcodeGeneratorWinFormsDotNetCoreDemo".
Select
.NET 6.0, and then press "Create".
Now, all auto-generated files could be found in the WinForms project solution explorer.
2. Install Barcode Generator Library dll and NuGet Package
Add OnBarcode Barcode Generator C# library for WinForms Core DLL reference "
OnBarcode.Barcode.Common.dll".
Right-click "Dependencies" in the Solution Explorer, and select "Manage NuGet Packages".
Select "Browse" and use the search control to find "System.Drawing.Common" from the package source "nugget.org".
Choose the version 6.0.0 or later to install the package.
Check "Packages" in the Solution Explorer to ensure the installation is success.
3. Design the user interface with WinForms controls added
Use Toolbox to add controls to the form "Form1".
Change the property Size of control "Form1" to "720, 480" in the Properties window first.
List of controls to add (total 12 controls)
- A Label with a TextBox for data message
- A Label with a TextBox for barcode width
- A Label with a TextBox for resolution
- A Label with a Button for fore color
- A Label with a Button for back color
- A Button for show barcode result
- A PictureImage
Step 1: add a Label control and TextBox control for data message
Change property Text of control "label1" to "Data Message:" and Location to "15, 33".
Change TextBox control name to "tbData", then set properties Text to "QRCode", Location to "125, 30", and Size to "200, 23".
Step 2: add Label and TextBoxe controls for barcode width and resolution.
Change property Text of control "label2" to "Width (inch):" and Location to "15, 62".
Change TextBox control name to "tbWidth", then set properties Text to "1.0", Location to "125, 59", and Size to "100, 23".
Change property Text of control "label3" to "Resolution (dpi):" and Location to "15, 91".
Change TextBox control name to "tbResolution", then set properties Text to "300", Location to "125, 88", and Size to "100, 23".
Now the Windows Form will be like:
Step 3: add Label and Button controls for fore color and back color.
Change property Text of control "label4" to "Fore Color:" and Location to "15, 121".
Change Button control name to "btForeColor", then set properties Text to "", and Location to "125, 117".
Change property Text of control "label5" to "Back Color:" and Location to "15, 150".
Change Button control name to "btBackColor", then set properties Text to "", and Location to "125, 146".
Form view after step 3.
Step 4: add Button and PictureBox controls for update and preview barcode on the form.
Change Button control name to "btShow", then set properties Text to "Show", and Location to "100, 225".
Change PictureBox control name to "pictureBoxPreview", then set properties Location to "331, 12", and Size to "361, 417".
Below is the final view of the Form.
4. Add behind code to the Form.
Select "View Code" from the menu to open the Form1.cs window.
Replace all contents in the Form1.cs file by following codes.
using OnBarcode.Barcode;
namespace OnBarcodeGeneratorWinFormsDotNetCoreDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Initial controls
this.btForeColor.BackColor = Color.Black;
this.btBackColor.ForeColor = Color.White;
updatePictureBox();
}
private void btForeColor_Click(object sender, EventArgs e)
{
ColorDialog colorDialog = new ColorDialog();
if (colorDialog.ShowDialog() == DialogResult.OK)
{
this.btForeColor.BackColor = colorDialog.Color;
updatePictureBox();
}
}
private void btBackColor_Click(object sender, EventArgs e)
{
ColorDialog colorDialog = new ColorDialog();
if (colorDialog.ShowDialog() == DialogResult.OK)
{
this.btBackColor.BackColor = colorDialog.Color;
updatePictureBox();
}
}
private void btShow_Click(object sender, EventArgs e)
{
updatePictureBox();
}
private void updatePictureBox()
{
try
{
QRCode barcode = new QRCode();
barcode.DataMode = QRCodeDataMode.Auto;
barcode.Data = this.tbData.Text;
barcode.AutoResize = true;
barcode.UOM = UnitOfMeasure.INCH;
barcode.BarcodeWidth = float.Parse(this.tbWidth.Text);
barcode.BarcodeHeight = float.Parse(this.tbWidth.Text);
barcode.Resolution = int.Parse(this.tbResolution.Text);
barcode.ForeColor = this.btForeColor.BackColor;
barcode.BackColor = this.btBackColor.BackColor;
// Note: Image in PictureBox would ignore resolution in Bitmap.
this.pictureBoxPreview.Image = barcode.drawBarcode();
}
catch { }
}
}
}
5. Add Click event to all controls
Select "btForeColor" Button control in the Form and switch to Event tab in the Properties window, and then add Click event "btForeColor_Click".
Select "btBackColor" Button control, and then add Click event "btBackColor_Click".
Select "btShow" Button control, and then add Click event "btShow_Click".
6. It is done. Now press "Ctrl+F5" to run the project.
Screenshot for the Demo application.
Customize barcode settings and refresh the barcode image on the Windows Form.