Skip to main content

Bar Code Options

  • 2 minutes to read

The library allows you to set options specific for each code type and generate an image for use in your application or for inserting into a document.

When generating an image, the library allows you to set its orientation, color, quality, and also allows you to specify whether or not an image displays a bar code text. You can include top and bottom captions with arbitrary text formatted using font, color and alignment options.

Bar Code Options

Options common for all bar codes (BarCode.BackColor, BarCode.ForeColor, BarCode.RotationAngle etc.) are accessible via the properties of the BarCode object.

Options specific to a certain symbology are accessible via the properties of a BarCodeOptions object exposed by the BarCode.Options property.

The code sample below generates a bar code and specifies its options:


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

static void Main(string[] args)
    // Create a QR code.
    BarCode barCode = new BarCode();
    barCode.Symbology = Symbology.QRCode;
    barCode.CodeText = "";
    barCode.BackColor = Color.White;
    barCode.ForeColor = Color.Black;
    barCode.RotationAngle = 0;
    barCode.CodeBinaryData = Encoding.Default.GetBytes(barCode.CodeText);

    barCode.Options.QRCode.CompactionMode = QRCodeCompactionMode.Byte;
    barCode.Options.QRCode.ErrorLevel = QRCodeErrorLevel.Q;
    barCode.Options.QRCode.ShowCodeText = false;
    barCode.DpiX = 72;
    barCode.DpiY = 72;
    barCode.Module = 2f;

    // Save the barcode as an image.
    barCode.Save("BarCodeImage.png", System.Drawing.Imaging.ImageFormat.Png);
    // Open the image in the default viewer.
    Process.Start(new ProcessStartInfo("BarCodeImage.png") { UseShellExecute = true });
See Also