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
- private void button1_Click(object sender, EventArgs e)
- {
- OpenFileDialog openFileDialog1 = new OpenFileDialog();
-
- if (openFileDialog1.ShowDialog() == DialogResult.OK)
- {
- string filename = openFileDialog1.FileName;
- txtPath.Text = filename;
- string str = File.ReadAllText(filename);
- string str1 = str.Substring(2368);
- string STR2 = str1.Remove(953);
- textencode.Text = STR2;
- }
- }
Press F4 on invoice textbox and search the keypress event and double click on it.
- private void text_Invoice_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.Handled = !Char.IsDigit(e.KeyChar))
- {
- MessageBox.Show("Allow only 10 digit numeric values ");
- }
- }
and save the file as given name in invoice text box.
Click on QrCode Generate button.
- private void btn_encoder_Click(object sender, EventArgs e)
- {
-
- string path = @"d:\\QRCode\\" + text_Invoice.Text+".bmp";
- MessagingToolkit.QRCode.Codec.QRCodeEncoder encoder = new MessagingToolkit.QRCode.Codec.QRCodeEncoder();
- encoder.QRCodeScale = 8;
-
- Bitmap bmp = new Bitmap(encoder.Encode(textencode.Text),new Size(200,200));
-
- pictureBox.Image = bmp;
-
- var newBmp = bmp.Clone(new Rectangle(0, 0, bmp.Width, bmp.Height), PixelFormat.Format8bppIndexed);
-
- folderBrowserDialog1.SelectedPath = path;
-
- if (text_Invoice.Text.Trim() == string.Empty)
- {
- MessageBox.Show("Please enter Invoce number before generate the QRCode");
- return;
- }
- else if (textencode.Text.Trim() == string.Empty)
- {
- MessageBox.Show("Please select the text file ");
- return;
- }
- else
- {
- newBmp.Save(path, ImageFormat.Bmp);
- MessageBox.Show("QRCode "+ text_Invoice.Text+ ".bmp save sucessfully");
-
- textencode.Text = "";
- text_Invoice.Text = "";
- }
- }
Save image in D:/Qrcode as a given name in invoice textbox