Generate dynamic QRCode from ListView using VB.Net in Windows Application

Last Reply 6 months ago By nirmal90

Posted 7 months ago

I want to generate a Dynamic QR code in VB.Net. In a form, I am having a listview. I want to generate a Dynamic QR code base on the ListView.

I have tried using the textbox and it's generating the QR Code. Now i want to generate a QR Code of the ListView

    Private Sub btnQRCode_Click(sender As Object, e As EventArgs) Handles btnQRCode.Click
        Dim objqrcode As QRCodeEncoder = New QRCodeEncoder
        Dim img As Image
        Dim btm As Bitmap
        Dim str As String
        If txtMessage.Items.Count <> 0 Then
            For x As Integer = 0 To txtMessage.Items.Count - 1
                str = txtMessage.Items(x).SubItems(0).Text
                str = txtMessage.Items(x).SubItems(1).Text 
                str = txtMessage.Items(x).SubItems(2).Text
                ''str = txtMessage.Items(x).SubItems(3).Text + txtMessage.Items(x).SubItems(4).Text +
                str = txtMessage.Items(x).SubItems(5).Text
                ''  VL &= "JWI DT &ensp; - " + txtMessage.Items(x).SubItems(6).Text + "<br>" + "<br>"

                '  VL &= "  enter   " + System.Environment.NewLine + vbNewLine + vbCrLf
            Next
            objqrcode.QRCodeScale = 2
            img = objqrcode.Encode(str)
            btm = New Bitmap(img)
        End If
        'str = cmbChallNo.Text + ")" + "  " + cmbLItemType.Text + " - " + txtDate.Text
        'img = objqrcode.Encode(str)
        'btm = New Bitmap(img)
        btm.Save("qrimage.jpg")
        PictureBox1.ImageLocation = "qrimage.jpg"
    End Sub

 

Posted 6 months ago

 Dear Sir

Please find the Below answer found.

   Public Sub QRCoderGen2()
        Dim str As String = ""
        If lstBillItem.Items.Count <> 0 Then
            str &= "Supplier Name:- C. K. ENGINEERING WORKS" + vbCrLf
            str &= "GSTIN of the Supplier:- 27AKMPG6795Q1Z1" + vbCrLf
            str &= "Invoice Number:- " + txtBillNo.Text + vbCrLf
            str &= "Invoice Date:- " + dtpBDate.Text + vbCrLf
            str &= "Recipient Name:- " + cmbCompName.Text + vbCrLf
            str &= "GSTIN of the Recipient:- " + txtGSTNO.Text + vbCrLf
            str &= "Invoice Value:- " + txtSubTot.Text + vbCrLf + vbCrLf
            str &= "Description of Dispatch Items" + vbCrLf
            For x As Integer = 0 To lstBillItem.Items.Count - 1

                str &= "Sr.No.:- " + lstBillItem.Items(x).SubItems(0).Text + ")  "
                str &= "ItemCode - " + lstBillItem.Items(x).SubItems(2).Text + " | "
                str &= "ItemName - " + lstBillItem.Items(x).SubItems(3).Text + " | "
                str &= "HSN - " + lstBillItem.Items(x).SubItems(23).Text + " | "
                str &= "ItemQty - " + lstBillItem.Items(x).SubItems(8).Text + "  " + lstBillItem.Items(x).SubItems(6).Text + vbCrLf

                ''  VL &= "JWI DT &ensp; - " + txtMessage.Items(x).SubItems(6).Text + "<br>" + "<br>"

                '  VL &= "  enter   " + System.Environment.NewLine + vbNewLine + vbCrLf
            Next
        End If
        Dim body As String = str
        'str = cmbChallNo.Text + ")" + "  " + cmbLItemType.Text + " - " + txtDate.Text

        'img = objqrcode.Encode(str)
        'btm = New Bitmap(img)
        '' objqrcode.QRCodeScale = 2
        ''img = objqrcode.Encode(body)
        ''QrCodeImgControl1.Text = str
        Dim barcodewriter As BarcodeWriter = New BarcodeWriter
        Dim encodingoptions As EncodingOptions = New EncodingOptions() With {
            .Width = 300,
            .Height = 300,
            .Margin = 0,
            .PureBarcode = False
                }
        encodingoptions.Hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H)
            barcodewriter.Renderer = New BitmapRenderer
        barcodewriter.Options = encodingoptions
        barcodewriter.Format = BarcodeFormat.QR_CODE
        Dim bitmap As Bitmap = barcodewriter.Write(str)
        Dim logo As Bitmap = New Bitmap("E:\TestingNewFeature\ckelogo.png")
        Dim g As Graphics = Graphics.FromImage(bitmap)
        g.DrawImage(logo, New Point((bitmap.Height - logo.Height) / 2, (bitmap.Height - logo.Height) / 2))
        PictureBox1.Image = bitmap
        'barcodewriter.Format = BarcodeFormat.QR_CODE
        'barcodewriter.Options = New EncodingOptions() With {
        '.Width = 100,
        '.Height = 100,
        '}

    End Sub