Generating BarCode And QRCode In Winforms Application

INTRODUCTION

In this article, I am going to explain how to generate Barcode and QRcode in a Windows.Forms Application using Visual Studio 2017.

STEP 1 - Start the Project

Let us start the project. Open Visual Studio2017--->Start New Project--->Windows.Forms Application and name it  BarcodeSample.

Windows Forms
 
STEP 2 - Drag and Drop Controls onto the form

By default, the Designer page will get opened. Now, drag and drop controls like Picture Box, TextBox, Label and Buttons from the ToolBox onto the form in Visual Studio 2017.

Windows Forms 

Change the border style of Picture Box as Fixed 3D so that the PictureBox looks like the below screenshot. Change the text of the buttons to Barcode and QRCode. Change the text of the labels as corresponding to the buttons as Barcode and  QRcode. After changing the properties of the Control, the form looks like this.

Windows Forms 

STEP 3 - Download and Install Zen Barcode Framework from Nuget Packages

For generating the Barcode and QRCode, we need to download and install Zen Barcode Framework from NuGet packages. Click project----> Manage NuGet Packages--->Browse Zen Barcode Framework---->Download and install Zen Barcode FrameWork.

Windows Forms

Windows Forms 

STEP 4 - Coding for the Button Click Event

Follow the code given below in the screenshot for generating the Barcode and QRCode in Windows.Forms using Visual Studio 2017.
  1. private void button1_Click(object sender, EventArgs e)  
  2.       {  
  3.           Zen.Barcode.Code128BarcodeDraw barcode = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum;  
  4.           pictureBox1.Image = barcode.Draw(textBox1.Text, 50);  
  5.   
  6.       }  
  7.   
  8.       private void button2_Click(object sender, EventArgs e)  
  9.       {  
  10.           Zen.Barcode.CodeQrBarcodeDraw qrcode = Zen.Barcode.BarcodeDrawFactory.CodeQr;  
  11.           pictureBox1.Image = qrcode.Draw(textBox2.Text, 50);  
  12.                 
  13.       }  
Windows Forms

STEP 5 - Output for the Project

Compile and Run the code. The following output will be obtained. Enter some text in the text box corresponding to the Barcode Label. Now, the Barcode is generated in the PictureBox for the text entered in the Textbox when the Barcode Button is clicked. 

Windows Forms 
 
Compile and Run the Code. The following output will be obtained. Enter some text in Textbox corresponding to the QRcode Label. Now, the QRcode is generated in the PictureBox for the text entered in the Textbox when the QRcode Button is clicked.

Windows Forms 

Summary

Hence, Barcode and QRcode are generated for the text entered in the Textbox. I hope you find this article interesting. In my next article, I will explain how to work with Tab Control in Windows.Forms using Visual Studio 2017. In case of any error or problem with the code, feel free to comment. 

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now