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; }