public class PrintClass { readonly PrintDocument printdoc1 = new PrintDocument(); readonly PrintPreviewDialog previewdlg = new PrintPreviewDialog(); Bitmap MemoryImage; private readonly Panel panel_; public PrintClass(Panel pnl) { panel_ = pnl; printdoc1.PrintPage += (printdoc1_PrintPage); MemoryImage = new Bitmap(pnl.Width, pnl.Height); } private int page = 0; private void GetPrintArea(Control pnl) { page = 0; MemoryImage = new Bitmap(pnl.Width, pnl.Height); pnl.DrawToBitmap(MemoryImage, new Rectangle(0, 0, pnl.Width, pnl.Height)); } private void printdoc1_PrintPage(object sender, PrintPageEventArgs e) { var pagearea = e.PageBounds; e.Graphics.DrawImage(MemoryImage, new Rectangle(e.PageBounds.Location, e.PageBounds.Size), new Rectangle(e.PageBounds.Location.X, e.PageBounds.Height * page, e.PageBounds.Width, e.PageBounds.Height), GraphicsUnit.Pixel); e.HasMorePages = e.PageBounds.Height * (page+1) < panel_.Size.Height; page++; } public void Print() { GetPrintArea(panel_); previewdlg.Document = printdoc1; previewdlg.ShowDialog(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)