How to generate Barcode & QR Code in C#
By FoxLearn 11/19/2024 3:04:11 PM 8.46K
Zen Barcode is a simple and lightweight barcode library for generating 1D and 2D barcodes such as QR codes.
How to generate Barcode & QR Code in C#?
Open Visual Studio, click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "BarcodeExample" and then click OK
Right-click on your project in the Solution Explorer, then select Manage NuGet Packages -> Search zen barcode -> Install
Drag and drop PictureBox, Label, TextBox, Button controls from Visual Toolbox onto your form designer, then design your form as below.
After installing the package, make sure you have the necessary using directive in your code.
Add code to handle your form
public partial class Form1 : Form { public Form1() { InitializeComponent(); } // c# generate barcode private void btnBarcode_Click(object sender, EventArgs e) { // Create the barcode object Zen.Barcode.Code128BarcodeDraw barcode = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum; // Display the barcode in the PictureBox pictureBox.Image = barcode.Draw(txtBarcode.Text, 50); } // c# generate qrcode private void btnQRCode_Click(object sender, EventArgs e) { // Create the qrcode object Zen.Barcode.CodeQrBarcodeDraw qrcode = Zen.Barcode.BarcodeDrawFactory.CodeQr; // Display the qrcode in the PictureBox pictureBox.Image = qrcode.Draw(txtQRCode.Text, 50); } }
VIDEO TUTORIAL