Printing range

ManicCW

Well-known member
Joined
Jul 21, 2005
Messages
428
Location
Mostar
Programming Experience
Beginner
How to print range of pages from .net using printdialog and printpreview (not printpreviewdialog!!!)? I can't seem to get it to work. I'm using vb.net 2005 express for now.

And also how to jump to page on combo selected index changed (again do not explain me printpreviewdialog i dont use it because i have no control over it!).

Tnx

P.S. Why is there no printing category in this forum???
 
P.S. This should have been posted in "Reporting/Printing" section.

PrintDialog, PrintPreviewDialog and PrintPreview Control all work through same PrintDocument object. The PrintDocument PrintPage event is as you know where you set up the logic to print every page, be it the full range or a limited range. In this event you set up 'markers' to know where in the print process you are, if you have printed first page you know how much is printed so far, then next time this event is called for page 2 you know where to continue etc.. The same thing goes for printing a range, you calculate where in the data you have to start if printing from "page 2", and you calculate where to stop when reached "page 4" for instance.

If you can't control the PrintDocument events, then I would suggest reading any number tutorials about general printing in .Net until you do so, because this is the way it is done in .Net.
 
PrintDialog has properties for AllowSelection = True and AllowSomePages = True

Programatically:
PrintDialog1.PrinterSettings.PrintRange.SomePages
PrintDialog1.PrinterSettings.FromPage
PrintDialog1.PrinterSettings.ToPage

If PrintRange is .SomePages, use the FromPage and ToPage properties to determine what pages should be printed.

That's all I have, nothing on PrintPreviewDialog and PrintPreview Control, sorry.
 
I attach an example that is very basic, but it contains all you need to see how the dynamics of the PrintPage event works, plus working with some page settings.

It allows use of PrintPreviewDialog and PrintDialog, both with option to print/preview all pages or a range of pages.

Notice how the very simple 7 code lines PrintPage event handler handles all variations of printing/preview and full/partial page range.

"Homework" is to create your own Printing Preview Dialog with the PrintPreview Control, with the knowledge from this example :)
 

Attachments

Back
Top