C# 怎样实现条码标签的批量打印
现在的情况是可以打印一个条码标签
调用,PrintDocument.print
如果我要批量实现条码标签的打印,应该怎么写?
代码如下:
private void button1_Click(object sender, EventArgs e) //按钮事件
{
strCon = "server=192.168.1.57;uid=sa;pwd=123;database=LonkingJiXie";
SqlConnection sqlCon = new SqlConnection();
sqlCon.ConnectionString = strCon;
sqlCon.Open();
SqlCommand sqlCom = new SqlCommand("select * from TestTM", sqlCon);
SqlDataReader sqlDR = sqlCom.ExecuteReader();
bool ifcom = sqlDR.Read();
if (ifcom)
{
WLcode = sqlDR[0].ToString();
WLname = sqlDR[1].ToString();
TMcode = sqlDR[2].ToString();
}
PrintPreviewDialog ppwDlg = new PrintPreviewDialog();
PrintDocument prtDoc = new PrintDocument();
ppwDlg.Document = prtDoc;
prtDoc.PrintPage += new PrintPageEventHandler(prtDoc_PrintPage);
if (ppwDlg.ShowDialog() != DialogResult.OK)
{
prtDoc.PrintPage -= new PrintPageEventHandler(prtDoc_PrintPage);
return;
}
}
----------------------document.pintpage事件
//printdocument.printpage 事件
Graphics g = e.Graphics;
e.Graphics.Clip = new Region(new Rectangle(10, 2, 800, 200));
g.PageUnit = GraphicsUnit.Millimeter;
Font drawFont = new Font("宋体", 14);
Font drawLGFont = new Font("方正艺黑简体", 8);
SolidBrush drawBrush = new SolidBrush(Color.Black);
g.DrawString("Lonking 龙工", drawLGFont, drawBrush, 10, 5);
SizeF FZ = g.MeasureString("Lonking 龙工", drawFont, e.MarginBounds.Width);
g.DrawString(WLname + ":", drawFont, drawBrush, 10, 5 + FZ.Height);
SizeF dd = g.MeasureString(WLname + ":", drawFont, e.MarginBounds.Width);
g.DrawString(WLcode, drawFont, drawBrush, 10 + dd.Width, 5 + dd.Height);
Pen penLine = new Pen(new SolidBrush(Color.Black), 0.2f);
//g.DrawLine(penLine, 10, 10, 190, 10);
//g.DrawLine(penLine, new PointF(20.0f, Convert.ToSingle(20.0f + dd.Height)), new PointF(Convert.ToSingle(20.0f + 2 * dd.Width), Convert.ToSingle(20.0f + dd.Height)));
//g.DrawRectangle(penLine, 10,10, 190, 50); //左,上,右,下 坐标,高、宽
Code39 _Code39 = new Code39();
_Code39.Height = 60;
_Code39.Magnify = 1;
_Code39.ViewFont = new Font("宋体", 10);
System.Drawing.Image _CodeImage = _Code39.GetCodeImage(TMcode, Code39.Code39Model.Code39Normal, true);
g.DrawImage(_CodeImage, 5, 10 + FZ.Height);