先引用barcodelib控件
using System.Threading;
using System.Drawing.Printing;
private void button1_Click(object sender, EventArgs e)
{DialogResult result = MessageBox.Show("你确定要打印条码一?", "信息提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (result == DialogResult.OK)
{
Control.CheckForIllegalCrossThreadCalls = false;
//打印次数
printDocument1.PrinterSettings.Copies = Convert.ToInt16(txt_print.Text.Trim());
//换成多线程方式
if (thre == null)
{
thre = new Thread(this.printDocument1.Print);
thre.Start();
}
if (thre.ThreadState == ThreadState.Stopped)
{
thre.Abort();
GC.Collect();
thre = new Thread(this.printDocument1.Print);
thre.Start();
}
}
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
打印内容 为 局部的 this.groupBox1
//Bitmap _NewBitmap = new Bitmap(pane_Barcode.Width, pane_Barcode.Height);
//pane_Barcode.DrawToBitmap(_NewBitmap, new Rectangle(0, 0, _NewBitmap.Width, _NewBitmap.Height));
//e.Graphics.DrawImage(_NewBitmap, 0, 0, _NewBitmap.Width, _NewBitmap.Height);