C# Exercises

Home AgriMetSoft About Contact

Generate a QR code in your WinForms c#

	    
using QRCoder;
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;

namespace QR_Code
{
  public partial class Form1 : Form
  {
    // NuGet\Install-Package QRCoder -Version 1.4.1
    public Form1()
    {
      InitializeComponent();
    }
    private void generate_Click(object sender, EventArgs e)
    {
      QRCodeGenerator qrGenerator = new QRCodeGenerator();
      QRCodeData qrCodeData = qrGenerator.CreateQrCode(textBox1.Text, QRCodeGenerator.ECCLevel.Q);
      QRCode qrCode = new QRCode(qrCodeData);
      Bitmap qrCodeImage = qrCode.GetGraphic(20);
      pictureBox1.Image = qrCodeImage;
    }
    private void save_Click(object sender, EventArgs e)
    {
      using (SaveFileDialog saveFileDialog = new SaveFileDialog() { Filter = @"PNG|*.png" })
      {
        if (saveFileDialog.ShowDialog() == DialogResult.OK)
        {
          pictureBox1.Image.Save(saveFileDialog.FileName);
          MessageBox.Show("The file is saved.");
        }
      }
    }
  }
}
		
	 


Download the project of Visual Studio 2013 in DropBox Download


Quick ∧ Easy Guide to Creating a QR Code in your WinForms C# Application!


List of Exercises