Solved

PrintDocument EndPrint event is not being called on cancel

Posted on 2011-02-19
2
1,697 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…

828 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