C# printdocument 打印问题
我做的是标签打印,数据库只有100条数据的话,第一页打满的话,要实现接着下一页打。
我下面,这样是的话,变死循环且,都是打印第一页的
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();
Graphics g = e.Graphics;
Font drawLGFont = new Font("方正艺黑简体", 20);
Font drawFont = new Font("宋体", 14);
SolidBrush drawBrush = new SolidBrush(Color.Black);
int Y = 0;
while (sqlDR.Read())//循环读取每一行
{
WLcode = sqlDR[0].ToString();
WLname = sqlDR[1].ToString();
TMcode = sqlDR[2].ToString();
e.Graphics.Clip = new Region(new Rectangle(10, 2, 200, 500));
g.PageUnit = GraphicsUnit.Millimeter;
g.DrawString("标签打印测试", drawLGFont, drawBrush, 10, 5+Y);
SizeF FZ = g.MeasureString("标签打印测试", drawFont, e.MarginBounds.Width);
g.DrawString(WLname + ":", drawFont, drawBrush, 10, 10 + FZ.Height+Y);
SizeF SZ = g.MeasureString(WLname + ":", drawFont, e.MarginBounds.Width);
g.DrawString(WLcode, drawFont, drawBrush, 10 + SZ.Width, 10+ SZ.Height+Y);
SizeF TZ = g.MeasureString(WLcode + ":", drawFont, e.MarginBounds.Width);
//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, 10, 20 + TZ.Height+Y);
Y = Y + 40;
}
e.HasMorePages = true; //这边这样加的话变,死循环,预览时,都是第一页的内容
sqlDR.Dispose();
sqlCom.Dispose();
sqlCon.Dispose();
sqlCon.Close();