|
-
Sep 21st, 2013, 04:26 AM
#3
Thread Starter
Randalf the Red
Re: VS 2010 PrintDocument Printing to non-default printer
The sequence of events goes (or should go) thus:
I create a PrintDocument (which has an empty/null PageSettings property)
I assign the PrintDocument instance to the PrintDialog and show the PrintDialog to the user
User makes changes in the PrintDialog such as select printer, select number of pages to print etc.
After user clicks Print in the PrintDialog, the PrintDocument.PageSettings should now reflect whatever the user has selected.
So far so good.
The PrintDocument has the BeginPrint and Print_Page event handlers assigned. The moment user clicks Print, the BeginPrint event handler is called - I do my print initialization here.
After BeginPrint, for ever page being printed, the PrintPage event is called. This event takes two arguments: sender - the object which generated this event, and PrintEventArgs which contains more information about the printing - such as the page settings etc. and most importantly the graphics object for the printer.
Now in the PrintPage event, when I check the Sender object, it shows the printer selected by the user by default, but when I examine PrintEventArgs, it always shows the default printer configured in Windows. This means the correct printer object raised the event, but the graphics object which I have to use is of a different printer.
After associating the PrintDocument to the PrintDialog, when the user clicks Print, I check the code and sure enough, PrintDocument.PageSettings.PrinterSettings.PrinterName reflects the printer selected by the user. So I am not sure there's anything wrong in my code.
For now, I have simply set whichever printer I want to print to as the default printer and things are going ok. However this still bugs me a lot.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|