QR Code
- 3 minutes to read
Short Description
A QR Code (QR is the abbreviation for Quick Response) is a two-dimensional code, readable by QR scanners, mobile phones with a camera, and smartphones. QR Code can encode textual, numeric and binary data.
Bar Code Properties
The type of a bar code control’s Symbology property is QRCodeGenerator.
The following properties are specific to the QR type.
XRBarCode.AutoModule/BarCodeControl.AutoModule
Gets or sets whether the Module property value should be calculated automatically based upon the barcode’s size.
QRCodeGenerator.CompactionMode
Gets or sets whether numeric, alpha-numeric or byte information should be used as the bar code’s data.
QRCodeGenerator.ErrorCorrectionLevel
Gets or sets the amount of redundancy built into the bar code’s coding, to compensate for calculation errors.
-
Gets or sets the bar code’s size.
-
Specifies the image that overlays the QR code.
Examples
The following code creates a QR Code 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 CreateQRCodeBarCode(string BarCodeText) {
// Create a bar code control.
XRBarCode barCode = new XRBarCode();
// Set the bar code's type to QRCode.
barCode.Symbology = new QRCodeGenerator();
// Adjust the bar code's main properties.
barCode.Text = BarCodeText;
barCode.Width = 400;
barCode.Height = 150;
// If the AutoModule property is set to false, uncomment the next line.
barCode.AutoModule = true;
// barcode.Module = 3;
// Adjust the properties specific to the bar code type.
((QRCodeGenerator)barCode.Symbology).CompactionMode = QRCodeCompactionMode.AlphaNumeric;
((QRCodeGenerator)barCode.Symbology).ErrorCorrectionLevel = QRCodeErrorCorrectionLevel.H;
((QRCodeGenerator)barCode.Symbology).Version = QRCodeVersion.AutoVersion;
return barCode;
}
To add the XRBarCode to a report band, handle the report’s XRControl.BeforePrint event.
using System.Drawing.Printing;
// ...
private void XtraReport1_BeforePrint(object sender, PrintEventArgs e) {
this.Detail.Controls.Add(CreateQRCodeBarCode("012345678"));
}