How to Generate QR Code in C# Windows Application
QR (Quick Response) Code Generator using C#.NET with Source Code
QR Code generate is a program that generates text into QR Code Image using the messaging toolkit QR code and developed using C# net. and it allows the export image and saves it into your system.
for example, POS System generates QR Code for each item produced and creates a tracking feature that has a QR Code Scanning and by that, the system user will have a better experience using the system.
Features
- Generate QR Code
- Export QR Code as an Image
Tools used:
- Labels
- Picture Box
- Buttons
Library Used
- MessagingToolkit.QRCode
The below code is the one I used to generate QR Code
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 MessagingToolkit.QRCode.Codec; using System.IO; using System.Threading; namespace QR_Code_Generator { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void qrcodeGen() { try { QRCodeEncoder qrCode = new QRCodeEncoder(); qrCode.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; qrCode.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.L; this.PictureBox1.Image = qrCode.Encode(this.txtCode.Text, System.Text.Encoding.UTF8); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void Form1_Load(object sender, EventArgs e) { } private void btnGenerate_Click(object sender, EventArgs e) { try { qrcodeGen(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void btnExport_Click(object sender, EventArgs e) { try { if (this.PictureBox1.Image != null) { // this.PictureBox1.Image.Save(System.IO.Path.Combine((new Microsoft.VisualBasic.Devices.ServerComputer()).FileSystem.SpecialDirectories.MyDocuments, this.txtCode.Text + ".jpg")); MessageBox.Show("QR is successfully saved"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
Post A Comment:
0 comments: