Get Started - Generate a QR Code
- 3 minutes to read
Important
You need a license to the DevExpress Office File API or DevExpress Universal Subscription to use these examples in production code. Refer to the DevExpress Subscription page for pricing information.
Perform the steps below to get started with the Barcode Generation API.
Create a new Windows Forms App (.NET Framework) project.
Add references to the DevExpress.Docs.v19.2.dll and DevExpress.Data.v19.2.dll assemblies.
Drop the Button and PictureBox items from the Toolbox onto the form.
Add the following code to the method that handles the button’s Click event.
using System; using System.Drawing; using System.Text; using DevExpress.BarCodes; //... private void button1_Click(object sender, EventArgs e) { this.pictureBox1.Image = null; 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; this.pictureBox1.Image = barCode.BarCodeImage; }
Run the project and click the button. The PictureBox control displays the resulting QR code.
Start Microsoft Visual Studio and create a new Console Application (.NET Core) project.
Install the DevExpress.WindowsDesktop.Document.Processor NuGet package.
Right-click the project in the Solution Explorer and select Edit Project File.
Change the project’s SDK attribute to Microsoft.NET.Sdk.WindowsDesktop and set the UseWindowsForms option to true.
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.0</TargetFramework> <UseWindowsForms>true</UseWindowsForms> </PropertyGroup> </Project>
Paste the code below in the Main method of the Program.cs file (Main procedure of the Module1.vb file for Visual Basic).
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 = "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", System.Drawing.Imaging.ImageFormat.Png); // Open the image in the default viewer. Process.Start(new ProcessStartInfo("BarCodeImage.png") { UseShellExecute = true }); }
Run the project. The resulting image is shown below: