protected override void OnPrintPage(PrintPageEventArgs e) { float yPos = Top;// +5.9f; bool morePages = false; int elementsOnPage = 0; int printIndex = 0; while (printIndex < _printObjects.Count) { IPrintable printObject = (IPrintable)_printObjects[printIndex]; PrintElement printElement = new PrintElement(printObject); printElement.Print(null); printElement.Draw(Left, yPos, Right, e.PageBounds.Width, e.Graphics); yPos += this.Height; printIndex++; elementsOnPage++; } e.HasMorePages = morePages; }
// ShowPreview - show a print preview... //public void ShowPreview() //{ // // now, show the print dialog... // PrintPreviewDialog dialog = new PrintPreviewDialog(); // dialog.Document = this; // // show the dialog... // dialog.ShowDialog(); //} // OnBeginPrint - called when printing starts //protected override void OnBeginPrint(PrintEventArgs e) //{ //} // OnPrintPage - called when printing needs to be done... protected override void OnPrintPage(PrintPageEventArgs e) { //foreach (IPrintable printObject in _printObjects) //{ // PrintElement element = new PrintElement(printObject); // _printElements.Add(element); // element.Print(e.Graphics); //} float headerHeight = 0; if (Header != null) { headerHeight = Header.CalculateHeight(e.Graphics, Left, e.PageBounds.Width); Header.Draw(Left, Top, Right, e.PageBounds.Width, e.Graphics); } float yPos = Top + headerHeight; bool morePages = false; int elementsOnPage = 0; while (_printIndex < _printElements.Count) { PrintElement element = (PrintElement)_printElements[_printIndex]; float height = element.CalculateHeight(e.Graphics, Left, e.PageBounds.Width); element.Draw(Left, yPos, Right, e.PageBounds.Width, e.Graphics); yPos += height; _printIndex++; elementsOnPage++; } float footerHeight = 0; if (Footer != null) { footerHeight = Footer.CalculateHeight(e.Graphics, Left, e.PageBounds.Width); Footer.Draw(Left, yPos, Right, e.PageBounds.Width, e.Graphics); } e.HasMorePages = morePages; yPos += footerHeight; }