Generowanie QR kodu w C# WinForms

Program do generowanie kodów QR z biblioteką Barcode

Link do strony z biblioteką: https://ironsoftware.com/csharp/barcode/tutorials/csharp-barcode-image-generator/

W designerze należy dodać:

TextBox
Button (wraz z Click eventem)
PictureBox

using System;
using System.Drawing;
using System.Windows.Forms;
using IronBarCode;

namespace Test1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();   
        }

        int num = 0;
        void GenerateQr() 
        {
            string qrtext = textBox1.Text;
            if(qrtext.Length > 0)
            {
                string path = @"qr_images/qr" + num + ".png";
                //string path = $"qr_images/qr{num}.png";
                GeneratedBarcode qr = IronBarCode.BarcodeWriter.CreateBarcode(qrtext, BarcodeEncoding.QRCode);
                qr.AddAnnotationTextAboveBarcode("ASTRAJA");
                qr.AddAnnotationTextBelowBarcode(qrtext);
                qr.SaveAsPng(path);               
                pictureBox1.Image = Image.FromFile(path);
                //pictureBox1.ImageLocation = path;            
                num++;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            GenerateQr();
        }
    }
}
Scroll to Top