Solved

PrintDocument EndPrint event is not being called on cancel

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

943 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

10 Experts available now in Live!

Get 1:1 Help Now