Form data printing problem
-
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?
-
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?
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.
-
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.
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.
-
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.
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.
-
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.