public float CalculateHeight() { float width = this.DefaultPageSettings.PaperSize.Width; float headerHeight = 0; if (Header != null) { headerHeight = Header.CalculateHeight(g, Left, width); } float yPos = Top + headerHeight; int calPrintIndex = 0; while (calPrintIndex < _printElements.Count) { PrintElement element = (PrintElement)_printElements[_printIndex]; float height = element.CalculateHeight(g, Left, width); yPos += height; calPrintIndex++; } float footerHeight = 0; if (Footer != null) { footerHeight = Footer.CalculateHeight(g, Left, width); } yPos += footerHeight; yPos += Top; return(yPos); }
// 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; }