Hi everyone !!!!!
here is the example to generate QR Image.
Step 1 : Open visual studio --> Start New Project (using C# or VB)
Step 2: In the solution explorer 'Right Click', add new item then from the online template (if Nugate not install) search QRCode Library
Step 3 : install QRCode library to your project
Step 4 : after install the QRCode Library , write your code as below
here is the example to generate QR Image.
Step 1 : Open visual studio --> Start New Project (using C# or VB)
Step 2: In the solution explorer 'Right Click', add new item then from the online template (if Nugate not install) search QRCode Library
Step 3 : install QRCode library to your project
Step 4 : after install the QRCode Library , write your code as below
Step 5 : write the code behind on button click event
using the namespace
using MessagingToolkit.QRCode;
using MessagingToolkit.QRCode.Codec;
private void generateQR(object sender, EventArgs e)
{
string QRstring ;
string QRImagestring ;
QRstring = txtPartNo.Text + "{" + txtQuantity.Text + "{" + txtUnit.Text + "{" +
txtVendor.Text + "{" + txtTradingCode.Text + "{" + txtPONo.Text + "{" +
txtInviceNo.Text + "{" + txtDeltaSerialNo.Text;
QRImagestring = txtVendor.Text + txtPONo.Text + txtInviceNo.Text +
DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() +
DateTime.Now.Day.ToString() + DateTime.Now.Minute.ToString() +
DateTime.Now.Second.ToString();
QRCodeEncoder encode = new QRCodeEncoder();
Bitmap img = encode.Encode(QRstring);
img.Save("C:\\QRImage\\" + QRImagestring + ".jpg", ImageFormat.Jpeg);
QRImage.Image = Image.FromFile("C:\\QRImage\\" + QRImagestring + ".jpg");
lblPartNo.Text = txtPartNo.Text;
lblQuantity.Text = txtQuantity.Text;
lblUnit.Text = txtUnit.Text;
lblVendor.Text = txtVendor.Text;
lblPONo.Text = txtPONo.Text;
lblInviceNo.Text = txtInviceNo.Text;
}
Step 6 : Build your project
that all the above scenario can create the QR Image for ready to scan.
Print the above QR code into small printer on print button
1. Add printDialog and print Document into your code or drag and drop to window page
2. after it, copy the below code on button click event
//-----------button click ----------//
private void printQR(object sender, EventArgs e)
{
System.Drawing.Printing.PrintDocument doc = new
System.Drawing.Printing.PrintDocument();
doc.PrintPage += new
System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
doc.Print();
}
//------------function for print the panel having the print detail----------------//
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
Bitmap bmp = new Bitmap(panel1.Width, panel1.Height, panel1.CreateGraphics());
panel1.DrawToBitmap(bmp, new Rectangle(0, 0, panel1.Width, panel1.Height));
RectangleF bounds = e.PageSettings.PrintableArea;
float factor = ((float)bmp.Height / (float)bmp.Width);
e.Graphics.DrawImage(bmp, bounds.Left, bounds.Top, bounds.Width, factor * bounds.Width);
}
this will print the above created QR code into small printer for scan the details

No comments:
Post a Comment