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
- Add .NET Barcode Generator DLL for WinForms to Toolbox.
Setup a new .NET Windows Forms project, right-click Toolbox, select Choose Items..., and click Browse... to find OnBarcode.Barcode.WinForms.dll. Then, you may find four controls added to toolbox, namely LinearWinForm, DataMatrixWinForm, PDF417WinForm, and QRCodeWinForm. - Drag DataMatrixWinForm and drop it to your windows form and a Data Matrix barcode will be printed on the form instantly.
If you want to print other barcode types, please drag and drop respective control to your windows form. Among them, LinearWinForm will generate & print all 20+ linear barcodes including Codabar, Code 39, Code 128, EAN-8, EAN-13, EAN-128, Interleaved 2 of 5, ISBN, ISSN, UPC-A, UPC-E and so on. - You can also add a textbox on the form for inputting barcode encoding message
How to create barcodes in WPF using C#
Here is a sample C# source code to create barcodes in a WPF app.
// Sample code for creating a Barcode BitmapImage.
private BitmapImage createLinear()
{
// Create a sample Linear barcode
OnBarcode.Barcode.Linear linear = new OnBarcode.Barcode.Linear();
linear.Type = OnBarcode.Barcode.BarcodeType.CODE128;
linear.Data = "Code 128";
linear.UOM = OnBarcode.Barcode.UnitOfMeasure.PIXEL;
linear.Resolution = 96;
linear.X = 2;
linear.Y = 100;
// Render the barcode to a Bitmap object.
System.Drawing.Bitmap bitmap = linear.drawBarcode();
// Convert Bitmap object to BitmapImage object.
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = ms;
bi.EndInit();
return bi;
}
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.