Results 1 to 2 of 2

Thread: How can I get printdocument pagecount without show in printpreviewdialog?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2018
    Posts
    77

    How can I get printdocument pagecount without show in printpreviewdialog?

    I just need to get Printdocument PageCount. I like to get it only with Button_click with in a messagebox. I can get result only if I use with calling PrintPreviewDialog.showDialog windows.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How can I get printdocument pagecount without show in printpreviewdialog?

    You seem to be under the impression that there is some magic to it. There isn't. The only way a PrintDocument could calculate the page count is to perform a print run and see how many time the PrintPage event is raised. The number of times the PrintPage event is raised is determined by YOUR logic. That means that, if you want to know what the page count will be without actually performing a print run, YOU need to apply that same logic to the data being printed OUTSIDE of the printing code. For instance, let's say that you have a DataGridView that you intend to print. In the PrintPage event handler, you loop through the rows and print 100 at a time and, when done, you check whether there are still rows to print and set e.HasMorePages accordingly. How do you think you would calculate the number of pages without performing a print run? You'd get the number of rows in the grid and dive by 100, right? You need to apply the same principle to your data. The PrintDocument is for printing. If you don't want to print, leave it alone.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width