Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Form data printing problem

Form data printing problem

Scheduled Pinned Locked Moved C#
questionhelp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mark F
    wrote on last edited by
    #1

    I created a UserControl that contains three RichTextBox controls. I added a PrintDocument property, and the methods required to print (Print, PrintPage, BeginPrint, etc). I have a loop that iterates the data and loads three strings in the RichTextBox controls, one to each control, and then calls PrintDocument.Print(). It should then print that page and get the next three strings of data to print. This works fine for the first page, but the other pages don't print. After calling PrintDocument.Print() the program returns to the main form that called the UserControl print method. How do I continue iterating through my loop to print more pages?

    L 1 Reply Last reply
    0
    • M Mark F

      I created a UserControl that contains three RichTextBox controls. I added a PrintDocument property, and the methods required to print (Print, PrintPage, BeginPrint, etc). I have a loop that iterates the data and loads three strings in the RichTextBox controls, one to each control, and then calls PrintDocument.Print(). It should then print that page and get the next three strings of data to print. This works fine for the first page, but the other pages don't print. After calling PrintDocument.Print() the program returns to the main form that called the UserControl print method. How do I continue iterating through my loop to print more pages?

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, the general answer is: in the PrintPage handler, you should set PrintPageEventArgs.HasMorePages; however it might be more complex than that when printing list-oriented controls (including RichTextBox) as there may be more data in them than is visible at any one time on your Form. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      Getting an article published on CodeProject should be easier and faster.


      M 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, the general answer is: in the PrintPage handler, you should set PrintPageEventArgs.HasMorePages; however it might be more complex than that when printing list-oriented controls (including RichTextBox) as there may be more data in them than is visible at any one time on your Form. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        Getting an article published on CodeProject should be easier and faster.


        M Offline
        M Offline
        Mark F
        wrote on last edited by
        #3

        Luc Pattyn wrote:

        you should set PrintPageEventArgs.HasMorePages;

        I already thought of that. I also thought of setting the printrange to currentpage and then repeatedly call Print. Even that failed.

                pagesLeft = this.Print( e );
        
                if ( pagesLeft < cardsToPrint.Count )
                {
                    e.HasMorePages = true;
                }
                else
                    e.HasMorePages = false;
        

        The Print() method calls Graphics.DrawString() and draws the strings on the PrintDocument graphics rect. For a single page it works perfectly.

        L 1 Reply Last reply
        0
        • M Mark F

          Luc Pattyn wrote:

          you should set PrintPageEventArgs.HasMorePages;

          I already thought of that. I also thought of setting the printrange to currentpage and then repeatedly call Print. Even that failed.

                  pagesLeft = this.Print( e );
          
                  if ( pagesLeft < cardsToPrint.Count )
                  {
                      e.HasMorePages = true;
                  }
                  else
                      e.HasMorePages = false;
          

          The Print() method calls Graphics.DrawString() and draws the strings on the PrintDocument graphics rect. For a single page it works perfectly.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          This is what I suggest as a test: keep things as simple as possible. Hence use a boolean class member:

          bool firstPage=true;

          then do:

          e.HasMorePages=firstPage;
          firstPage=false;

          That should print two pages, no matter what. Then take it from there. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          Getting an article published on CodeProject should be easier and faster.


          M 1 Reply Last reply
          0
          • L Luc Pattyn

            This is what I suggest as a test: keep things as simple as possible. Hence use a boolean class member:

            bool firstPage=true;

            then do:

            e.HasMorePages=firstPage;
            firstPage=false;

            That should print two pages, no matter what. Then take it from there. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            Getting an article published on CodeProject should be easier and faster.


            M Offline
            M Offline
            Mark F
            wrote on last edited by
            #5

            I'll give it a try. Thanks!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups