我有一个包含信息的datagridview表
a | b
--+--
3 | 3
4 | 4
5 | 5
如何使用c#中的打印功能在第一页上打印3,3,在第二页上打印4,4,在第三页上打印5,5,依此类推?
private void printDocTicket_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
float point = 60;
for (int x = 0; x < DGVUpload.Rows.Count; x++)
{
point += 60;
e.Graphics.DrawString(DGV["Sym3", x].Value.ToString(), new Font("Courier New", 30), Brushes.Black, 60 , point );
e.Graphics.DrawString(DGV["Sym4", x].Value.ToString(), new Font("Courier New", 30), Brushes.Black, 250, point);
if (x <= DGV.Rows.Count)
{
e.HasMorePages = false;
}
else
{
e.HasMorePages = true;
}
}
}
答案 0 :(得分:0)
在意识到e.HasMorePages重新启动PrintPage事件后修改代码,给了我想要的结果。
int i;
private void printDocTicket_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
float point = 60;
e.Graphics.DrawString(DGV["Sym3", x].Value.ToString(), new Font("Courier New", 30), Brushes.Black, 60 , point );
e.HasMorePages = true;
i++;
if(i == DGV.Rows.Count)
{
e.HasMorePages = false;
}
}