Solved

PrintDocument EndPrint event is not being called on cancel

Posted on 2011-02-19
2
1,657 Views
Last Modified: 2013-11-12
When I call "Print" on the PrintDocument object and the user clicks "Cancel" on the printer setup dialog, the "EndPrint" event is not fired.  It only fires if the user proceeds with the printing (and the printing completes).  Does anyone have any idea why this might be happening?

Thanks,
Nicole
private Action _callback;

 public void Print(FrameworkElement elementToPrint, string Title, Action callback )
{

_callback = callback;

	PrintDocument pd = new PrintDocument();
	pd.EndPrint += new EventHandler<EndPrintEventArgs>(pd_EndPrint);
	pd.PrintPage += (o,e)=>
	{
		e.PageVisual = elementToPrint;
				
		e.HasMorePages = false;
	};
	pd.Print(Title);
			
}
void pd_EndPrint(object sender, EndPrintEventArgs e)
{
_callback();
}

Open in new window

0
Comment
Question by:nicolees
2 Comments
 
LVL 4

Accepted Solution

by:
grishav earned 500 total points
ID: 34936994
Hi,
This is "by design" (though I agree that it's not the best design I've seen):
From the documentation of EndPrint event on MSDN
(http://msdn.microsoft.com/en-us/library/system.windows.printing.printdocument.endprint(v=vs.95).aspx)


"The EndPrint event will not occur if the user cancels the print operation from the print dialog box."
So I don't think you can use this event to catch this.
0
 

Author Closing Comment

by:nicolees
ID: 34937704
Thanks for that info, I agree that is not ideal!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now