QR Code Generator in VB.NET Tutorial and Source code

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:

  1. Microsoft Visual Studio 2008 – Above
  2. MessagingToolkit.Barcode.dll

The tutorial starts here:

  1. Download MessagingToolkit.Barcode.dll from the internet and save it to your preferred directory.
  2. Open Microsoft Visual Studio 2012
  3. Select a New Project on the File menu.
  4. Select Visual Basic, Windows Form Application then click OK.
  5. On the solution Panel, right click the “name of your project” then click add reference
QR Code Generator in VB.NET Tutorial and Source code - Step 5
QR Code Generator in VB.NET Tutorial and Source code – Step 5
  1. 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”
QR Code Generator in VB.NET Tutorial and Source code - Step 6
QR Code Generator in VB.NET Tutorial and Source code – Step 6

­

  1. Click “Ok” and we are ready now to design our form
  2. 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.
  1. 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.
  1. This is how we design the form. (Feel free to layout your own)
QR Code Generator in VB.NET Tutorial and Source code - Step 10
QR Code Generator in VB.NET Tutorial and Source code – Step 10

­­­

Figure 1. Design of the Form

  1. 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.

  1. 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.

QR Code Generator in VB.NET Tutorial and Source code - Final Output
QR Code Generator in VB.NET Tutorial and Source code – Final Output

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.

, , ,

Post navigation