UPC-A

  • 2 minutes to read

The Universal Product Code (UPC) is a barcode symbology that is widely used in the United States, Canada, Europe, Australia, New Zealand, and other countries for tracking trade items in stores.

Barcode - UPC-A

Refer to the following article for more information: Universal Product Code.

Add the Bar Code to a Report

  1. Drag the XRBarCode item from the DX.20.2: Report Controls tab and drop it onto the report.

  2. Set the XRBarCode control’s Symbology property to UPCA (an object of the UPCAGenerator type).

  3. Specify common barcode properties.

NOTE

The control does not verify the length of the assigned character string specified by the barcode control’s Text value. It is the developer’s responsibility to check that the passed string contains no more than 11 digits (the control calculates the last twelfth digit automatically). If the number of digits is less than 11, the leading zeroes are added to the resulting barcode.

Runtime Example

The following code creates the UPC-A barcode and specifies its properties.

NOTE

The complete sample project is available in the following repository: 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 CreateUPCABarCode(string BarCodeText) {
    // Create a bar code control.
    XRBarCode barCode = new XRBarCode();

    // Set the bar code's type to UPC-A.
    barCode.Symbology = new UPCAGenerator();

    // Adjust the bar code's main properties.
    barCode.Text = BarCodeText;
    barCode.Width = 275;
    barCode.Height = 200;

    return barCode;
}

To add the XRBarCode to a report band, handle the report’s BeforePrint event.

using System.Drawing.Printing;
// ...

private void XtraReport1_BeforePrint(object sender, PrintEventArgs e) {
    this.Detail.Controls.Add(CreateUPCABarCode("012345678"));
}