How to print qr code using c# windows form

Total Post:17

Points:119
C#
 1272  View(s)
Ratings:
Rate this:

I work in visual studio 2015 windows form application and i need to print qr code by using c#

How can i print qr code generation ?

I generated using the following code : 

if (textBox1.Text =="")  
          {  
               
              MessageBox.Show("Please Enter Value ","Error");  
              textBox1.Focus();  
          }  
          else  
          {   
          using (SaveFileDialog sv = new SaveFileDialog() { Filter = "JPEG|.jpg", ValidateNames = true })  
          {  
              if (sv.ShowDialog() == DialogResult.OK)  
              {  
                  MessagingToolkit.QRCode.Codec.QRCodeEncoder encoder = new MessagingToolkit.QRCode.Codec.QRCodeEncoder();  
                  encoder.QRCodeScale = 8;  
                  string encoding="UserName : " + textBox1.Text + "\r\n" + "CardNo : " + textBox2.Text + "\r\n" + "Address:" + textBox3.Text + "\r\n"+textBox5.Text;  
                  Bitmap bmp = encoder.Encode(encoding);  
                  pictureBox1.Image = bmp;  
                  bmp.Save(sv.FileName, ImageFormat.Jpeg);  
              }  
  
          }  
          }  
  
      }  
  1. Post:281

    Points:2003
    Re: How to print qr code using c# windows form

    Step 1. Download ( BarcodeLib.Barcode.RDLCReports.dll). 

     Click here  for Download BarcodeLib.Barcode.RDLCReports.dll

    after download add reference in your windows application. 

    Add a New Form1 .

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    using System.Data.OleDb;
    using System.Drawing.Imaging;
    using BarcodeLib.Barcode.RDLCReports;
    using BarcodeLib.Barcode;
    using Microsoft.Reporting.WinForms;
    
    namespace QRCode
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
    
                Merchant proc = new Merchant();
                var data = proc.GetProducts();
    
    
                ReportDataSource rds = new ReportDataSource("DataSet1", data);
                this.reportViewer1.LocalReport.DataSources.Add(rds);
                reportViewer1.LocalReport.ReportPath = @"D:\OldSystemfiles\Aditya-Extra-Work\QRCode\QRCode\Report1.rdlc";
                
                reportViewer1.LocalReport.Refresh();
    
    
    
                this.reportViewer1.RefreshReport();
            }
        }
    
        public class SampleClass
         {
             private string m_description;
             private int m_price;
             private byte[] m_bytes;
    
             public SampleClass(string description, int price, string data)
             {
                 m_description = description;
                 m_price = price;
                 //QRCodeRDLC barcode = new QRCodeRDLC();
                 // create a linear barcode object
                 LinearRDLC barcode = new LinearRDLC();
                 // set barcode type to Code 128
                 barcode.Type = BarcodeType.CODE128;
                 barcode.Data = data;
                 m_bytes = barcode.drawBarcodeAsBytes();
    
    
             }
    
             public byte[] Bytes
             {
                 get { return m_bytes; }
             }
    
             public string Description
             {
                 get
                 {
                     return m_description;
                 }
             }
    
             public int Price
             {
                 get
                 {
                     return m_price;
                 }
             }
         }
    
         public class Merchant
         {
             private List<SampleClass> m_products;
    
             public Merchant()
             {
                 m_products = new List<SampleClass>();
                 m_products.Add(new SampleClass("code128", 25, "code128"));
                 m_products.Add(new SampleClass("code39", 30, "code39"));
                 m_products.Add(new SampleClass("qrcode", 15, "qrcode"));
             }
    
             public List<SampleClass> GetProducts()
             {
                 return m_products;
             }
         }
    }
    

    Add a Data Set

    Add Report1.rdlc

    Drog Report Vieweron form1.

    Run Application

    Thanks.

      Modified On Dec-28-2016 07:21:23 AM

Answer