111,098
社区成员




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 打印多页
{
public partial class Form1 : Form
{
private int Pages;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)//同样的问题,连续打印时,第二次打印会把1,2页打印到同一页面
{
Pages = 0;
printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
printDocument1.Print();
}
void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//throw new NotImplementedException();
e.HasMorePages = true;
Pages++;
if (Pages == 1)
{
Image MyPic = Image.FromFile("相片.JPG");
e.Graphics.DrawImage(MyPic, 20, 40);
}
if (Pages == 2)
{
e.Graphics.FillPie(new SolidBrush(Color.AliceBlue), new Rectangle(40, 60, 300, 100), 30, 60);
}
if (Pages == 3)
{
e.HasMorePages = false;
e.Graphics.FillRectangle(new SolidBrush(Color.BurlyWood),new Rectangle(46,20,600,400));
}
if (Pages > 3)
e.HasMorePages = false;
}
}
}
if (Pages > 3)
e.HasMorePages = false;
之后,Pages跳过=3的退出机会,会无限添加新页。