c# - Print Preview of multiple pages not working -


i've seen numerous posts this. believe i'm following them, still having problem.

i'm doing in c# , i'm running windows 8.1.

i making multi-page print-out of contents of xml file. i'm not looping through of elements, i'm doing own formatting of them. there enough elements i'll end printing several pages, i'm getting stuck on getting page 2 content show on page 2. here's i'm doing.

int pageprinting;  private void butprint_click(object sender, eventargs e) {     pageprinting = 1;     printdocument1.printpage += this.printdocument1_printpage;     printpreviewdialog1.printpreviewcontrol.document = printdocument1;     printpreviewdialog1.show();     ((form)printpreviewdialog1).windowstate = formwindowstate.maximized; }    private void printdocument1_printpage(system.object sender, printpageeventargs e) {     point pnt = new point(0, 0);     switch (pageprinting)     {         case 1:             e.graphics.compositingquality = system.drawing.drawing2d.compositingquality.highquality;             e.graphics.clear(color.white);             printdocument1.defaultpagesettings.landscape = false;             pnt.x = 300;             e.graphics.drawstring("page 1 header", fntarialheader, brushes.black, pnt);             // more printing on page 1 ...                  pageprinting++;             e.hasmorepages = true;             break;          case 2:             e.graphics.drawstring("page 2 header", fntarialheader, brushes.green, pnt);             // more printing on page 2 ...              e.hasmorepages = false;             break;     } } 

i believe @ end of printing page 1, setting e.hasmorepages = true, exiting , returning print page 2. when view in print preview, both headers on page 1, page available. when hit print button on print preview dialog, page 2 printed only.

i wouldn't add printpage event handler every time click print button:

so comment out line, or move form's constructor it's wired once:

printdocument1.printpage += this.printdocument1_printpage; 

Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -