none
Force the printer to print to a new page RRS feed

  • Question

  • I have a situation where I want to force PrintDocument to start a new page even though the previous page is not full.  This would be like placing a page break in Word.  I have tried using (.HasMorePages) but to no avail.  The output has a combination of text and graphics if that makes a difference. Thanks.

    Thursday, February 1, 2007 2:48 PM

Answers

  • Setting 'HasMorePages' to true does not start a new page.

    A new page is started when the printpage event sub is exited

    AND  'HasMorePages' set to true.

    Friday, February 2, 2007 4:16 AM
  • Returning that property from your print delegate will simply instruct the print engine to reinvoke your delegate with a clean graphics canvas and print to another page.

    Sorry, perhaps the above should have been a little clearer ....

    The method you are doing the painting within is called once for each page that you wish to generate.  If you want the method to be called again, set e.HasMorePages = True and exit your method.  The print engine will call into your method with a clean canvas to paint the next page on.

    sub printpage(......)

    static curpage as integer = 1

    paintpage(curpage, e) ... etc

    if moretoprint then

    e.hasmorepages = true : curpage += 1

    else : curpage = 1

    end if

    end sub

    Please let me know if the above is unclear still

    Richard

    Friday, February 2, 2007 9:34 AM

All replies

  • Hi

    Can you explain why (or post your code) the HasMorePages = True does not work?

    Returning that property from your print delegate will simply instruct the print engine to reinvoke your delegate with a clean graphics canvas and print to another page.

    Richard

    Thursday, February 1, 2007 3:57 PM
  • The code is quite extensive so I will try to explain what I am doing.  The code preceeding the HasMorePages=true is a combination of .Graphics.DrawString, .Graphics.DrawLine and .Graphics.DrawImage methods.  I then set HasMorePages=true, in order to start a second page, set the line counter to 0 and then perform the additional .Graphics.DrawString methods.  The preview shows the subsequent text written over the preceeding text on the same page.  Hope this clarifies.
    Thursday, February 1, 2007 4:36 PM
  • Setting 'HasMorePages' to true does not start a new page.

    A new page is started when the printpage event sub is exited

    AND  'HasMorePages' set to true.

    Friday, February 2, 2007 4:16 AM
  • Returning that property from your print delegate will simply instruct the print engine to reinvoke your delegate with a clean graphics canvas and print to another page.

    Sorry, perhaps the above should have been a little clearer ....

    The method you are doing the painting within is called once for each page that you wish to generate.  If you want the method to be called again, set e.HasMorePages = True and exit your method.  The print engine will call into your method with a clean canvas to paint the next page on.

    sub printpage(......)

    static curpage as integer = 1

    paintpage(curpage, e) ... etc

    if moretoprint then

    e.hasmorepages = true : curpage += 1

    else : curpage = 1

    end if

    end sub

    Please let me know if the above is unclear still

    Richard

    Friday, February 2, 2007 9:34 AM