4,816
社区成员
发帖
与我相关
我的任务
分享
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++;
}