Back to Devexpress

BarCode Class

officefileapi-devexpress-dot-barcodes.md

latest4.0 KB
Original Source

BarCode Class

Represents a bar code for given data with the specified options.

Namespace : DevExpress.BarCodes

Assembly : DevExpress.Docs.v25.2.dll

NuGet Package : DevExpress.Document.Processor

Declaration

csharp
[DXLicenseDocs]
public class BarCode :
    IDisposable,
    IBasePrintable,
    IPrintingTarget
vb
<DXLicenseDocs>
Public Class BarCode
    Implements IDisposable,
               IBasePrintable,
               IPrintingTarget

Remarks

Use BarCode.CodeText or BarCode.CodeBinaryData properties to set the data to be represented by a bar code.

Specify the BarCode.Symbology property to define the bar code type. Note that each symbology has its own restrictions for the encoded data.

Symbology specifics are available by the BarCode ‘s BarCode.Options property.

The BarCode.BarCodeImage property gets an image that is the bar code.

You can use the BarCode.Print, BarCode.PrintDialog or the BarCode.ShowPrintPreview methods to print the bar code.

The BarCode.ExportToPdf method enables you to print a bar code to PDF.

The code sample below creates a QR code and displays it in a PictureBox.

csharp
using System;
using System.Text;
using DevExpress.BarCodes;
using DevExpress.Drawing;
using DevExpress.Drawing.Extensions;
//...

private void button1_Click(object sender, EventArgs e)
{
    this.pictureBox1.Image = null;

    BarCode barCode = new BarCode();
    barCode.Symbology = Symbology.QRCode;
    barCode.BackColor = Color.White;
    barCode.ForeColor = Color.Black;
    barCode.RotationAngle = 0;
    barCode.CodeBinaryData = Encoding.Default.GetBytes("https://www.devexpress.com/");
    barCode.Options.QRCode.CompactionMode = QRCodeCompactionMode.Byte;
    barCode.Options.QRCode.ErrorLevel = QRCodeErrorLevel.Q;
    barCode.Options.QRCode.ShowCodeText = true;
    barCode.DpiX = 72;
    barCode.DpiY = 72;
    barCode.Module = 2f;

    this.pictureBox1.Image = barCode.BarCodeImage.ConvertToGdiPlusImage();
}
vb
Imports System
Imports System.Text
Imports DevExpress.BarCodes
Imports DevExpress.Drawing
Imports DevExpress.Drawing.Extensions
'...

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    Me.pictureBox1.Image = Nothing

    Dim barCode As New BarCode()
    barCode.Symbology = Symbology.QRCode
    barCode.BackColor = Color.White
    barCode.ForeColor = Color.Black
    barCode.RotationAngle = 0
    barCode.CodeBinaryData = Encoding.Default.GetBytes("https://www.devexpress.com/")
    barCode.Options.QRCode.CompactionMode = QRCodeCompactionMode.Byte
    barCode.Options.QRCode.ErrorLevel = QRCodeErrorLevel.Q
    barCode.Options.QRCode.ShowCodeText = True
    barCode.DpiX = 72
    barCode.DpiY = 72
    barCode.Module = 2F

    Me.pictureBox1.Image = barCode.BarCodeImage.ConvertToGdiPlusImage()
End Sub

Implements

IDisposable

IBasePrintable

DevExpress.Printing.Native.IPrintingTarget

Inheritance

Object BarCode

See Also

BarCode Members

DevExpress.BarCodes Namespace