【发布时间】:2013-09-15 23:20:11
【问题描述】:
数据表 (dt) 包含我要打印的数据。一页可以容纳 15 行。该代码适用于第一页,但注释行不起作用,并且打印了无数页。谁能帮忙解决这个问题?
private void Doc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
for (int y = 0; y <= dt.Columns.Count; y++)
{
e.Graphics.DrawLine(Pens.Black, 50 + (y * 150), 150, 50 + (y * 150), 1000);
}
for (int x = 0; x < dt.Rows.Count; x++)
{
e.Graphics.DrawLine(Pens.Black, 50, 200 + (x * 50), 700, 200 + (x * 50));
}
for (int z = 0; z < dt.Rows.Count; z++)
{
for (int d = 0; d < dt.Columns.Count; d++)
{
string element = dt.Rows[z][d].ToString();
e.Graphics.DrawString(element, new Font("Arial", 14, FontStyle.Italic), Brushes.Black, 60 + (d * 150), 210 + (50 * Rows));
}
//if (z % 15 == 0)
//{ e.HasMorePages = true; Rows = 0; break; }
//else { e.HasMorePages = false; }
Rows++;
}
}
【问题讨论】:
-
注释行“不起作用”是什么意思?你的意思是 e.HasMorePages 总是返回 true 吗?
-
不,我的意思是 hasmorepages 返回无限页..第一页只返回第一行的数据。