c# - 如何打印每行打印在新页面中的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;
}
}
}
解决方案
在意识到 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;
}
}
推荐阅读
- python - 在文件练习中苦苦挣扎
- java - @OneToMany 两个表之间的关系,每个表都有复合主键
- php - 教义中的外键(Symfony)。如何将新孩子绑定到已经存在的父母?
- mysql - python mysql打印非空值
- vba - VBA 停止 OnTime 函数
- session - 松树脚本 - 自定义会话突破问题
- sql - groupby 在 oracle sql 中检查每个日期
- flutter - 如何将英雄小部件动画到另一个页面中轮播的第一个元素?
- ios - 如何处理:App Store Connect Operation Error (ERROR ITMS-90744: "Unsupported Xcode or SDK Version.)
- r - 在完全按照说明进行操作时创建自己的包时出错