protected override void OnBeginPrint(PrintEventArgs e) { // reset... _printElements = new ArrayList(); _pageNum = 0; _printIndex = 0; // go through the objects in the list and create print elements for each one... foreach (IPrintable printObject in _printObjects) { // create an element... PrintElement element = new PrintElement(printObject); _printElements.Add(element); // tell it to print... printObject.Print(element); } }
public void Print(PrintElement element) { element.NewPage(); }
protected override void OnPrintPage(PrintPageEventArgs e) { // adjust the page number... _pageNum++; // now, render the header element... float headerHeight = Header.CalculateHeight(this, e.Graphics); Header.Draw(this, e.MarginBounds.Top, e.Graphics, e.MarginBounds); // also, we need to calculate the footer height... // Drawing the footer is a similar deal, except this has to appear at the bottom of the page: float footerHeight = Footer.CalculateHeight(this, e.Graphics); Footer.Draw(this, e.MarginBounds.Bottom - footerHeight, e.Graphics, e.MarginBounds); // now we know the header and footer, we can adjust the page bounds... Rectangle pageBounds = new Rectangle(e.MarginBounds.Left, (int)(e.MarginBounds.Top + headerHeight), e.MarginBounds.Width, (int)(e.MarginBounds.Height - footerHeight - headerHeight)); float yPos = pageBounds.Top; // ok, now we need to loop through the elements... bool morePages = false; int elementsOnPage = 0; // registra a largura da página para calcular // a altura do bloco de impressão MarginBoundsWidth = e.MarginBounds.Width; while (_printIndex < _printElements.Count) { // get the element... PrintElement element = (PrintElement)_printElements[_printIndex]; if (element.isNewPage()) { morePages = true; _printIndex++; elementsOnPage++; break; } // how tall is the primitive? float height = element.CalculateHeight(this, e.Graphics); // will it fit on the page? if (yPos + height > pageBounds.Bottom) { // we don't want to do this if we're the first thing on the page... if (elementsOnPage != 0) { morePages = true; break; } } // now draw the element... element.Draw(this, yPos, e.Graphics, pageBounds); // move the ypos... yPos += height; //yPos = e.Graphics.ClipBounds.Bottom; // next... _printIndex++; elementsOnPage++; } // do we have more pages? e.HasMorePages = morePages; }
public void Print(PrintElement element) { // printa o corpo do relatório element.AddText(rowsbody); }