Code 128
- 2 minutes to read
Short Description
Code 128 is a very effective, high-density symbology which permits the encoding of alphanumeric data. The symbology includes a checksum digit for verification, and the bar code can also be verified character-by-character, allowing the parity of each data byte to be verified.
This symbology has been widely implemented in many applications where a relatively large amount of data must be encoded in a relatively small amount of space. Its specific structure also allows numerical data to be effectively encoded at double-density.
Bar Code Properties
The type of a bar code control’s Symbology property is Code128Generator.
The following property is specific to the Code 128 type.
-
Gets or sets the character set type for the bar code.
Examples
The following code creates a Code 128 bar code and specifies its main properties.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-add-a-bar-code-to-a-report-e167.
using System;
using System.Collections.Generic;
using System.Drawing.Printing;
using System.Windows.Forms;
using DevExpress.XtraPrinting.BarCode;
using DevExpress.XtraReports.UI;
// ...
public XRBarCode CreateCode128BarCode(string BarCodeText) {
// Create a bar code control.
XRBarCode barCode = new XRBarCode();
// Set the bar code's type to Code 128.
barCode.Symbology = new Code128Generator();
// Adjust the bar code's main properties.
barCode.Text = BarCodeText;
barCode.Width = 400;
barCode.Height = 100;
// Adjust the properties specific to the bar code type.
((Code128Generator)barCode.Symbology).CharacterSet = Code128Charset.CharsetB;
return barCode;
}
To add the XRBarCode to a report band, handle the report’s XRControl.BeforePrint event.