QR Code Generator For Government Invoice

Create a project name as QRCode Generator

 
Add the MessagingToolkit from manage nuget package option, just right click on QRcode generator project
 
 
 
Design for Window form
 
 
 Click on open txt File button to select the file as well as read the string from the file.
 
 
 Double click on open txt file Button and code as shown below
  1. private void button1_Click(object sender, EventArgs e)  
  2.         {  
  3.             OpenFileDialog openFileDialog1 = new OpenFileDialog();  
  4.   
  5.             if (openFileDialog1.ShowDialog() == DialogResult.OK)  
  6.             {  
  7.                 string filename = openFileDialog1.FileName;  
  8.                 txtPath.Text = filename;  
  9.                 string str = File.ReadAllText(filename);  
  10.                 string str1 = str.Substring(2368);  
  11.                 string STR2 = str1.Remove(953);  
  12.                 textencode.Text = STR2;  
  13.             }  
  14.         }  
 
Press F4 on invoice textbox and search the keypress event and double click on it.
  1. private void text_Invoice_KeyPress(object sender, KeyPressEventArgs e)  
  2.        {  
  3.            if (e.Handled = !Char.IsDigit(e.KeyChar))  
  4.            {  
  5.               MessageBox.Show("Allow only 10 digit numeric values ");  
  6.            }  
  7.        }  
and save the file as given name in invoice text box.
 
Click on QrCode Generate button.
  1. private void btn_encoder_Click(object sender, EventArgs e)  
  2.         {  
  3.   
  4.           string path = @"d:\\QRCode\\" + text_Invoice.Text+".bmp";  
  5.           MessagingToolkit.QRCode.Codec.QRCodeEncoder encoder = new MessagingToolkit.QRCode.Codec.QRCodeEncoder();  
  6.           encoder.QRCodeScale = 8;  
  7.           
  8.             Bitmap bmp = new Bitmap(encoder.Encode(textencode.Text),new Size(200,200));  
  9.               
  10.             pictureBox.Image = bmp;  
  11.              
  12.             var newBmp = bmp.Clone(new Rectangle(0, 0, bmp.Width, bmp.Height), PixelFormat.Format8bppIndexed);  
  13.             
  14.             folderBrowserDialog1.SelectedPath = path;  
  15.                               
  16.                 if (text_Invoice.Text.Trim() == string.Empty)  
  17.                 {  
  18.                     MessageBox.Show("Please enter Invoce number before generate the QRCode");  
  19.                     return  
  20.                 }  
  21.                 else if (textencode.Text.Trim() == string.Empty)  
  22.                 {  
  23.                     MessageBox.Show("Please select the text file ");  
  24.                     return;  
  25.                 }  
  26.                 else  
  27.                 {  
  28.                     newBmp.Save(path, ImageFormat.Bmp);  
  29.                     MessageBox.Show("QRCode  "+ text_Invoice.Text+ ".bmp save sucessfully");  
  30.   
  31.                     textencode.Text = "";  
  32.                     text_Invoice.Text = "";  
  33.                 }  
  34.              }  
 
Save image in D:/Qrcode as a given name in invoice textbox