110,570
社区成员
发帖
与我相关
我的任务
分享
#region 预览前绘图
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
int x = 0;
int y = 0;
int panHeight = panel1.Height;
decimal count = 0;
if (panHeight > 1123)
{
count = (panHeight / 1123) + 1;
}
Bitmap img = new Bitmap(panel1.Width,panHeight);
Graphics g = e.Graphics;
this.panel1.DrawToBitmap(img,new Rectangle(new Point(0,0),panel1.Size));
img.Save("c:\\save.jpg");
for (int i = 1; i < count; i++)
{
imgs = img.Clone(new Rectangle(x, y, 795, 1123), img.PixelFormat);
g.DrawImage(imgs, new Rectangle(0, 0, panel1.Width, 1123));
//imgs.Save("c:\\save"+i+".jpg");
y += 1123;
}
}
Bitmap imgs;
decimal count = 0;
decimal count1 = 0;
int x = 0;
int y = 0;
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
int panHeight = panel1.Height;
int height = 61;
if (panHeight > height)
{
count =(int)System.Math.Ceiling(panHeight /(double) height);
}
Bitmap img = new Bitmap(panel1.Width, panHeight);
Graphics g = e.Graphics;
this.panel1.DrawToBitmap(img, new Rectangle(new Point(0, 0), panel1.Size));
imgs = img.Clone(new Rectangle(x, y, 195, height), img.PixelFormat);
g.DrawImage(imgs, new Rectangle(0, 0, panel1.Width, height));
//imgs.Save("d:\\save" + count1.ToString() + ".jpg");
y += height;
count1 += 1;
img.Dispose();
imgs.Dispose();
if (count1 == count)
{
e.HasMorePages = false;
}
else
{
e.HasMorePages = true;
}
}