Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PrintDocument EndPrint event is not being called on cancel

Posted on 2011-02-19
2
Medium Priority
?
1,807 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 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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…
Loops Section Overview

972 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