110,006
社区成员




private int printIndex=0; //打印索引,下面调用要用到
private int pageSize=3; //有三张图片要打印
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
if (printIndex < pageSize)
{
e.Graphics.DrawImage(Image, 0, 0, photoWidth, photoHeight);
printIndex++;
//如果打印的页数还不足3页,那么我要继续打印
if (printIndex < pageSize)
{
e.HasMorePages = true;
}
}
else
{
e.HasMorePages = false;
}
}
拉一个printDocument控件到界面。
打印按钮的代码:
C# code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
private void button2_Click(object sender, EventArgs e)//执行打印
{
PrintDialog MyPrintDg = new PrintDialog();
MyPrintDg.Document = printDocument1;
if (MyPrintDg.ShowDialog() == DialogResult.OK)
{
try
{
printDocument1.Print();
}
catch
{ //停止打印
printDocument1.PrintController.OnEndPrint(printDocument1, new System.Drawing.Printing.PrintEventArgs());
}
}
}
另外还要设置PrintPage事件:
C# code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(pictureBox1.Image, 20, 20);
}