开发者

How to implement PrintRange.Selection in a PrintPage-handler?

开发者 https://www.devze.com 2023-02-04 20:23 出处:网络
I\'m trying to set up a print job completely by code. I have my own PrintPage and QueryPage handler and everything works quite well. But now I\'m stuck with the PageRange property of the PrinterSettin

I'm trying to set up a print job completely by code. I have my own PrintPage and QueryPage handler and everything works quite well. But now I'm stuck with the PageRange property of the PrinterSettings class.

For the property value 'PrintRange.Selection' the documentation says

开发者_开发问答

If PrintRange is PrintRange.Selection, then specify output only for the selected pages.

but couldn't find a way to do so. Simply not drawing anything for the not selected pages still prints an empty page. And setting cancel stops the whole print job. So how can the not-selected pages be left out?


Well, if you create multi-page documents then you should already have a page counter in your code. You set it to zero in the BeginPrint event handler and increment it in the PrintPage event handler. And use the value to figure out what page needs to be printed. You set e.HasMorePages to true if you are not done yet.

That strategy makes it simple to implement PrintRange. Just set set the page number in the BeginPrint event to the start page - 1 instead of 0. And avoid setting e.HasMorePages to true when the last page in the range was printed.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号