Skip to main content

Get Started - Generate a QR Code

  • 3 minutes to read

Important

You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use these examples in production code.

This article describes how to get started with the barcode generation component for .NET Framework and .NET Core.

Create a .NET Framework Application

  1. Create a new Windows Forms App (.NET Framework) project.

  2. Add references to the following libraries:

    • DevExpress.Docs.v24.1.dll
    • DevExpress.Drawing.v24.1.dll
    • DevExpress.Printing.v24.1.Core.dll
  3. Drop the Button and PictureBox items from the Toolbox onto the form.

  4. Add the following code to the method that handles the button’s Click event.

    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();
    }
    
  5. Run the project and click the button. The PictureBox control displays the resulting QR code.

    Barcode_Result

Create a .NET Core Application

  1. Start Microsoft Visual Studio and create a new Console Application (.NET Core) project.

  2. Install the DevExpress.Document.Processor NuGet package.

  3. Paste the code below in the Main method of the Program.cs file (Main procedure of the Module1.vb file for Visual Basic).

    using DevExpress.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 = "https://www.devexpress.com";
      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", DXImageFormat.Png);
      // Open the image in the default viewer.
      Process.Start(new ProcessStartInfo("BarCodeImage.png") { UseShellExecute = true });
    }
    
  4. Run the project. The resulting image is shown below:

Barcode_Result_NetCore3

See Also