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.
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.
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.
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.
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.
- private void button1_Click(object sender, EventArgs e)
- {
- Zen.Barcode.Code128BarcodeDraw barcode = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum;
- pictureBox1.Image = barcode.Draw(textBox1.Text, 50);
-
- }
-
- private void button2_Click(object sender, EventArgs e)
- {
- Zen.Barcode.CodeQrBarcodeDraw qrcode = Zen.Barcode.BarcodeDrawFactory.CodeQr;
- pictureBox1.Image = qrcode.Draw(textBox2.Text, 50);
-
- }
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.
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.
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.