C# printing multiple pages -
this code, works fine when print 1 page, when seek print doesn't fit onto 1 page doesn't start new page, accepts offset alter , starts writing on first page.
does know do?
private void printdocument_printpage(object sender, printpageeventargs e) { graphics graphic = e.graphics; font font = new font("courier new", 12); float fontheight = font.getheight(); int startx = 10; int starty = 10; int offset = 0; float pagewidth = e.pagesettings.printablearea.width; float pageheight = e.pagesettings.printablearea.height; foreach (string line in textrichtextbox.lines) { graphic.drawstring(line, font, new solidbrush(color.black), startx, starty + offset); offset += (int)fontheight;// + 5 if (offset >= pageheight - (int)fontheight) { e.hasmorepages = true; offset = 0; } } e.hasmorepages = false; }
you using api wrong, the doc says:
in printpage event handler, utilize graphics property of printpageeventargs class , document contents calculate line length , lines per page. after each page drawn, check see if lastly page, , set hasmorepages property of printpageeventargs accordingly. printpage event raised until hasmorepages false. also, create sure printpage event associated event-handling method.
you can't set hasmorepages
in loop, on exit of callback. callback called until set hasmorepages
false
c# printing
No comments:
Post a Comment