KA.Barcode for .NET WinForms
How to Print Data Matrix in .NET WinForms with Valid Data
Data Matrix source code to generate Data Matrix images using Barcode Generator for .NET WinForms
  • Written in managed C# with full integration into Microsoft Visual Studio 2005/2008/2010
  • Dynamically generate, print multiple 2d Data Matrix barcodes in Windows Forms in .NET
  • Input alphanumeric data in Data Matrix and create images in C#, VB.NET programming
  • Easy-to-use barcode generator provided, such as .NET WinForms barcode, barcode ASP.NET, barcode Java & Excel barcode
  • Draw and insert Data Matrix images in Crystal Report and RDLC Report
  • Also Support Data Matrix Data Modes including ASCII, C40,Text, X12, Edifact, and Base256
  • Select "Auto" to automatically encode Data Matrix with best data format according to input data
  • Compatible with ISO / IEC 16022 (2nd edition) Symbology Specification
  • Provide detailed Excel barcode integration, Java barcode tutorial & .NET barcode tutorial guides for users
  • Data Matrix ECI (Extended Channel Interpretation) function support to allow encoding other character sets
KA.Barcode Generator for .NET WinForms is a versatile barcode API SDK plugin that supports printing Data Matrix barcode pictures with best quality in .NET windows forms, Crystal Reports, C#, Visual Basic. NET class library, etc.
This page will guide you to encode valid ASCII characters with C#, VB.NET programming details.
Data Matrix Bar Code Introduction
Data Matrix, is also named as ECC200, 2D DataMatrix Barcode. Data Matrix is a standalone 2D symbology that is made up of square modules arranged within a perimeter finder pattern.

Valid Data

  • Standard ASCII characters: 0-127 including A-Z, a-z, 0-9, and special characters
  • Extended ASCII: values 128-255 (in accordance with ISO 8859-1)

Valid Length

  • Data Matrix barcode has a variable-length.
  • Alphanumeric data: up to 2335 characters (maximum)
  • 8-bit byte data: 1555 characters
  • Numeric data; 3116 digits
Data Matrix Data Encoding in .NET Windows Forms

Install Data Matrix Barcode Generator into .NET Project

  1. 1.
  2. 2.
    Add Reference: Add "KeepAutomation.Barcode.Window.dll" to your .NET WinForms project reference.
  3. 3.
    Add to Toolbox: Add BarCodeControl to your .NET Visual Studio toolbox.
Copy the following C#.NET Code onto your project to create, insert a Data Matrix barcode image
using KeepAutomation.Barcode.Bean;
BarCode datamatrix= new BarCode();
datamatrix. Symbology = Symbology. DataMatrix;
datamatrix.CodeToEncode = "C#DataMatrixImage";
datamatrix.X = 3;
datamatrix.Y = 3;
Dim datamatrix As KeepAutomation.Barcode.Bean.BarCode = New KeepAutomation.Barcode.Bean.BarCode

datamatrix.Symbology = KeepAutomation.Barcode.Symbology.DataMatrix
datamatrix.CodeToEncode = "vbDataMatrixGenerator"
datamatrix.X = 3
datamatrix.Y = 3
datamatrix.generateBarcodeToImageFile("C://datamatrix _vb.png")

Generating Data Matrix with ASCII Data Mode

KeepAutomation Data Matrix ASCII data mode allows you to encode double digit numerics, ASCII values 0-127, Extended ASCII values 128-255, which include numeric digits, upper-case letters, lower-case letters, and special characters.
datamatrix.DataMatrixDataMode = DataMatrixDataMode.ASCII;
datamatrix.CodeToEncode = "Data128#c";
datamatrix.DataMatrixDataMode = KeepAutomation.Barcode.DataMatrixDataMode.ASCII
datamatrix.CodeToEncode = "Data128#vb"

Printing Data Matrix with C40 Data Mode

C40 Data Mode for Data Matrix allows you to encode upper-case alphanumeric data. Follow the simple sample code below to convert alphanumeric string into a Data Matrix barcode image.
datamatrix.DataMatrixDataMode = DataMatrixDataMode.C40;
datamatrix.CodeToEncode = "DATA40";
datamatrix.DataMatrixDataMode = KeepAutomation.Barcode.DataMatrixDataMode.C40
datamatrix.CodeToEncode = "DATA40"

Creating Data Matrix with Text Data Mode

Text Data Mode for Data Matrix allows you to encode lower-case alphanumeric data, i.e. a-z, and 0-9. Here is the demo code to transform alphanumeric data text into a 2-dimensional Data Matrix graphic object.
datamatrix.DataMatrixDataMode = DataMatrixDataMode.Text;
datamatrix.CodeToEncode = "textdata";
datamatrix.DataMatrixDataMode = DataMatrixDataMode.Text
datamatrix.CodeToEncode = "textdata"

Drawing Data Matrix with X12 Data Mode

X12 Data Mode for Data Matrix allows you to encode ANSI X12 EDI data set, so you can input 0-9, A-Z and some punctuation marks. Copy the C#, VB.NET code below to switch to this data mode.
datamatrix.DataMatrixDataMode = DataMatrixDataMode.X12;
datamatrix.CodeToEncode = "DATAX12";
datamatrix.DataMatrixDataMode = KeepAutomation.Barcode.DataMatrixDataMode.X12
datamatrix.CodeToEncode = "DATAX12"

String Data Matrix with EDIFACT Data Mode

To encode alphanumeric data in Data Matrix, you can choose EDIFACT Data Mode, which allows you to encode ASCII values 32-94, so you can input 0-9, A-Z and many punctuation marks.
datamatrix.DataMatrixDataMode = DataMatrixDataMode.Edifact;
datamatrix.CodeToEncode = "ECC200";
datamatrix.DataMatrixDataMode = KeepAutomation.Barcode.DataMatrixDataMode.Edifact
datamatrix.CodeToEncode = "ECC200"

Making Data Matrix with Base 256 Data Mode

If you select Base 256 Data Mode for Data Matrix, then you can encode ASCII values 32-94, which include 0-9, A-Z and many punctuation marks. This data mode also support all byte values 0-255. Here is the C#, VB.NET demo code.
datamatrix.DataMatrixDataMode = DataMatrixDataMode.Base256;
datamatrix.CodeToEncode = "DM200";
datamatrix.DataMatrixDataMode = KeepAutomation.Barcode.DataMatrixDataMode.Byte256
datamatrix.CodeToEncode = "DM200"
Note: If you are not sure which data mode is proper for your encoding data, you can select Data Matrix Auto mode, KA.Barcode Generator for .NET WinForms will automatically print valid Data Matrix images according to your input data.
Data Matrix Data Encoding with Drag & Drop BarcodeControl
  1. 1.
    In "Choose Toolbox Items" form, click button "Browse...", and select KeepAutomation.Barcode.Windows.dll.
  2. 2.
    Now a BarCodeControl is added into your toolbox.
  3. 3.
    Drag and drop the BarCodeControl into the Forms and a Codabar image is generated.
  4. 4.
    Find Symbology" in the property panel and select DataMatrix.
  5. 5.
    Select proper data mode in the DataMatrixDataMode, for example, ASCII.
  6. 6.
    Then input numeric, alphanumeric or ASCII characters in "CodeToEncode" blanket.