473,396 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to implement a PrintRange functionnality in my PrintDocument ?

bp
Hi,

I try to use my own PreviewDialog with a PrinPreviewControl, to preview a
document of type MyPrintDocument, and I want to implement the PrintRange
functionnality (print some pages between 2 values).

I noticed that we can specified the PrintRange, FromPage and ToPage
properties of the PrintDocument.PrintSettings object, but, as said in MSDN :

"The FromPage, ToPage and PrintRange can also be set programmatically,
though the PrintDocument.PrintPage implementation is the same."

So I tried to do that in my class, inherited from PrintDocument, but I
failed ! In the PrintPage EventHandler, I made a treatment that paint
graphics for the specified pages, but I have blank pages ; I also tried to
specified a virtual printer for the page to ignore, in the QueryPageSettings
EventHandler, but it throws an exception...

So, please, how to proceed ?

Thanks in advance.

Jul 21 '06 #1
2 6600
Hi bp,

Can you post some code?
So I tried to do that in my class, inherited from PrintDocument, but I
failed
You don't need to derive from PrintDocument to print a range of pages. If you are deriving a class from PrintDocument for different
reasons then you should treat your document just as you would a PrintDocument.
I also tried to
specified a virtual printer for the page to ignore, in the QueryPageSettings
EventHandler, but it throws an exception...
You must post some code for anyone to help you with this problem.

--
Dave Sexton

"bp" <bp@discussions.microsoft.comwrote in message news:76**********************************@microsof t.com...
Hi,

I try to use my own PreviewDialog with a PrinPreviewControl, to preview a
document of type MyPrintDocument, and I want to implement the PrintRange
functionnality (print some pages between 2 values).

I noticed that we can specified the PrintRange, FromPage and ToPage
properties of the PrintDocument.PrintSettings object, but, as said in MSDN :

"The FromPage, ToPage and PrintRange can also be set programmatically,
though the PrintDocument.PrintPage implementation is the same."

So I tried to do that in my class, inherited from PrintDocument, but I
failed ! In the PrintPage EventHandler, I made a treatment that paint
graphics for the specified pages, but I have blank pages ; I also tried to
specified a virtual printer for the page to ignore, in the QueryPageSettings
EventHandler, but it throws an exception...

So, please, how to proceed ?

Thanks in advance.

Jul 22 '06 #2
bp wrote:
Hi,

I try to use my own PreviewDialog with a PrinPreviewControl, to preview a
document of type MyPrintDocument, and I want to implement the PrintRange
functionnality (print some pages between 2 values).

I noticed that we can specified the PrintRange, FromPage and ToPage
properties of the PrintDocument.PrintSettings object, but, as said in MSDN :

"The FromPage, ToPage and PrintRange can also be set programmatically,
though the PrintDocument.PrintPage implementation is the same."

So I tried to do that in my class, inherited from PrintDocument, but I
failed ! In the PrintPage EventHandler, I made a treatment that paint
graphics for the specified pages, but I have blank pages ; I also tried to
specified a virtual printer for the page to ignore, in the QueryPageSettings
EventHandler, but it throws an exception...

So, please, how to proceed ?
I made the same mistake when I started working with PrintDocument: I
thought that there was some magic behind the scenes that would take
care of the "Print page n" and "Print pages from n to m" functionality.

There isn't: you have to do it all yourself.

In your case, what that means is that the first time your PrintPage
event handler is called, you have to check the FromPage setting in the
page settings, and print _that_ page. It's up to _you_ to skip over the
first n - 1 pages on the first call and go directly to page n and print
that.

It's also up to you (as you've probably already guessed) to signal
"nothing more to print" when you've finished rendering page m.

The underlying PrintDocument doesn't understand page numbers, and
(wisely) doesn't assume that pages are simply numbered from 1. (They
may not be: consider a document with table of contents on pages i, ii,
iii, and iv, then the content is numbered 1, 2, 3, .... In that case,
"print 2 to 4" means print (by count) pages 6 to 8.) All that the
underlying framework does is pass you the numbers and let you work out
what to do.

So, on the very first call to PrintPage, you'll be handed a blank
graphics surface and the number FromPage 3, for example. It's up to you
to go through the motions of rendering pages 1 and 2 (without really
doing it) and then draw page 3 on the graphics surface and return. Or,
perhaps, you have some clever trick for knowing what belongs on page 3
without having to ghost-draw pages 1 and 2, in which case just go for
it.

Hope this helps.

Jul 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jeffry van de Vuurst | last post by:
Hi, I have a PrintDocument that I preview in a PrintPreviewControl. Now I run the app on a pc without any printers installed and when I want to preview the PrintDocument I get an...
3
by: Palli Olafs | last post by:
Hi Is it possible to save the PrintDocument as file without using a printer?
1
by: Frank Rizzo | last post by:
Hello, I have an OCX control on my WinForm (don't ask, i have to use it) and it generally works well. One of the methods of the OCX prints to an hDC (device context handle for history buffs). ...
0
by: Nigel | last post by:
The Visual Basic .NET Step by Step book has the following code and text: Imports System.Drawing.Printing Private Sub PrintText(ByVal sender As Object, ByVal ev As PrintPageEventArgs)...
0
by: active | last post by:
Dim mPD As PrintDocument Dim mPrinternameSaved As PrintDocument Public WriteOnly Property PrintDocument() As PrintDocument Set(ByVal value As PrintDocument) mPD = value mPrinternameSaved = mPD...
3
by: Mika M | last post by:
Hi all! I have made an application for printing simple barcode labels using PrintDocument object, and it's working fine. Barcode printer that I use is attached to the computer, and this...
2
by: Coen | last post by:
Hi, can anyone help me with the printrange functionality? The problem is: whatever I try allways all the pages are print (directly to the printer or via a preview control). The VS-Build in...
2
by: Steve | last post by:
I'm trying real hard to set the printer resolution for a PrintDocument. It appears that the printer is already set to 300 x 300 dpi, which is JUST what I want. But the Margins and PrintableArea...
1
by: kig25 | last post by:
Hello, When using the VB.NET PrintDocument class, I seem to be encountering an issue where the sub pd_PrintPage handles PrintDocument.PrintPage (upon continuing if HasMorePages = true) will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.