如何在每行打印在新页面中的地方打印datagridview?

时间:2018-08-31 17:52:11

标签: c# printing datagridview

我有一个包含信息的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;
            }
        }
    }

1 个答案:

答案 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;
    }
}