再问:关于打印ListView分页的问题!!!!

galaxy_1981 galaxy_1981 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
C# WinForm 开发环境VS2010,想实现分页打印ListView中的所有数据,代码如下:


int CurPrintPage = 1;
int count = 0; //行计数器

private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics g = e.Graphics; //获得绘图对象
float yPosition = 0; //绘制字符串的纵向位置
float leftMargin = e.MarginBounds.Left; //左边距
float topMargin = e.MarginBounds.Top; //上边距
Font printFont = this.textBox.Font; //当前的打印字体
SolidBrush myBrush = new SolidBrush(Color.Black);//刷子

int Pages = Lst.Items.Count / 9 + 1;//计算页面数量


while (count < 9)//每页最多打印3行
{
yPosition = topMargin + (count * printFont.GetHeight(g));
g.DrawString(Lst.Items[count].Text, printFont, myBrush, leftMargin, yPosition, new StringFormat());
g.DrawString(Lst.Items[count].SubItems[1].Text, printFont, myBrush, (leftMargin + 100), yPosition, new StringFormat());
count++;

if (CurPrintPage == Pages)
{
e.HasMorePages = false;
}
else
{
e.HasMorePages = true;
}
}


CurPrintPage++;
}



预览的时候,只有第一页是有数据的,其他都是空白,请问代码哪里出了问题??

请指点一下啊!!
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
galaxy_1981
图表区 4,818 成员 14,133 内容