日期:2014-05-18 浏览次数:21113 次
必要的类:
using System.Drawing.Printing;
我的打印代码放在一个Button里:
private void button1_Click(object sender, EventArgs e)
{
PrintDocument pdDocument = new PrintDocument();
pdDocument.PrintPage += new PrintPageEventHandler(PrintDocument_PrintPage);
//pdDocument.DefaultPageSettings.Landscape = true;
//此处更改页面为横向打印
pdDocument.Print();
}
private void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
{
e.HasMorePages = true; //此处打开多页打印属性
il++; //il是一个计数器,即页数
Bitmap bmp = new Bitmap(this.Width, this.Height);
//生成一个BMP对象
this.DrawToBitmap(bmp, new Rectangle(Point.Empty, this.Size));
//将当前界面转成BMP图片
Image PrintImage = (Image)bmp.Clone();
//将BMP转换成Image对象