数据表 (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++;
}
}