Hi everyone I am making inventory management software with the ability to create/print barcodes. My form looks like this:
Upon generating a barcode (with the data being that is in the text box). I also would like that data to be printed under the barcode. This is my 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;
namespace InventoryManagementSystem
{
public partial class Barcode : Form
{
public Barcode()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Zen.Barcode.Code128BarcodeDraw barcode = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum;
myPicturebox.Image = barcode.Draw(textBox1.Text, 50);
}
private void button2_Click(object sender, EventArgs e)
{
Zen.Barcode.CodeQrBarcodeDraw qrcode = Zen.Barcode.BarcodeDrawFactory.CodeQr;
myPicturebox.Image = qrcode.Draw(textBox2.Text, 50);
}
private void myPrintDocument2_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Bitmap myBitmap1 = new Bitmap(myPicturebox.Width, myPicturebox.Height);
myPicturebox.DrawToBitmap(myBitmap1, new Rectangle(0, 0, myPicturebox.Width, myPicturebox.Height));
e.Graphics.DrawImage(myBitmap1, 0, 0);
myBitmap1.Dispose();
}
private void btnPrint_Click(object sender, EventArgs e)
{
System.Drawing.Printing.PrintDocument myPrintDocument2 = new System.Drawing.Printing.PrintDocument();
PrintDialog printDialog1 = new PrintDialog();
myPrintDocument2.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(myPrintDocument2_PrintPage);
printDialog1.Document = myPrintDocument2;
if (printDialog1.ShowDialog() == DialogResult.OK)
{
myPrintDocument2.Print();
}
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnClear_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
}
}
}
What would be the best way to paint whatever textbox1.text is on the picture box, under the barcode? Thanks!