QR Code Generator in VB.NET Tutorial and Source code
Problem
Create a Windows Form Application program in Visual Basic.Net that will allow users to generate and save an image of QR Code.
Description
This tutorial will allow the user to generate a qr code by entering a string in the text box and will be displayed at the picture box as a QR Code. the user will be able to save the image of the qr code.
Before the tutorial the following are required to start:
- Microsoft Visual Studio 2008 – Above
- MessagingToolkit.Barcode.dll
The tutorial starts here:
- Download MessagingToolkit.Barcode.dll from the internet and save it to your preferred directory.
- Open Microsoft Visual Studio 2012
- Select a New Project on the File menu.
- Select Visual Basic, Windows Form Application then click OK.
- On the solution Panel, right click the “name of your project” then click add reference
- On the reference manager, Click Browse on the left panel and check the MessagingToolkit.Barcode.dll, if it doesn’t appear, then click the Browse button on the bottom. Search and select for MessagingToolkit.Barcode.dll then click “Add”
- Click “Ok” and we are ready now to design our form
- We need to design our form by the following controls:
- 1 label – label for the Code text box
- 1 text box – text box for the Code.
- 2 Command Button – 1 button to save the barcode to a directory and 1 button to generate the barcode to the picture box.
- 1 Picture Box – picture box where the barcode is displayed.
- We will also name our form controls in this way:
- txtText is the name of the textbox for textbox.
- cmdSave is the name of the button for save.
- cmdGenerate is the name of the button to generate the QR Code.
- pbQrCodeImg is the name of the picture box where the QR Code will be displayed.
- This is how we design the form. (Feel free to layout your own)
Figure 1. Design of the Form
- Double click the Generate Button and paste the following code.
Code here
Dim Generator As New MessagingToolkit.Barcode.BarcodeEncoder Generator.BackColor = Color.White Generator.LabelFont = New Font("Arial", 7, FontStyle.Regular) Generator.IncludeLabel = True Generator.CustomLabel = txttext.Text Try pbQrCodeImg.Image = New Bitmap(Generator.Encode(MessagingToolkit.Barcode.BarcodeFormat.QRCode, txttext.Text)) Catch ex As Exception pbQrCodeImg.Image = Nothing End Try
End Code
Code Explanation:
The code above will load the QRCode barcode from the MessagingToolkit.Barcode.BarcodeEncoder.dll, then it reads the string from the text box and display it to the picture box.
- Double click the Save Buttton and paste the following code.
Code here
Dim SD As New SaveFileDialog SD.FileName = "Visual Qr Code Generator" SD.Filter = "PNG Files Only(*.png)|*.png" If SD.ShowDialog() = Windows.Forms.DialogResult.OK Then Try pbQrCodeImg.Image.Save(SD.FileName, System.Drawing.Imaging.ImageFormat.Png) MsgBox("Image Has been Save", MsgBoxStyle.Information) Catch ex As Exception End Try
End Code
Code Explanation:
The code will show a Save file Dialogue from an initial Directory and will save the image in a .png image file extension.
Author:
Name: Charlie Devera
Email Address: charliedevera000@gmail.com
Free Download Source code (QR Code Generator in VB.NET)
You may visit our facebook page for more information, inquiries and comments.
Hire our team to do the project.