G
Guest
My app uses PrintPreviewDialog to allow the user to preview and print. If
the user selects print from the toolbar, and the current printer settings are
set to print to a file, a "Print to File" dialog asks them to enter a
filename. If at this point they press Cancel, they get an unhandled
exception (see below). What is strange is that I have a catch for the
exception, and all seems OK when debugging, but it is not handled when the
end user does this.
Any ideas why the exception is not caught?
[XP Pro SP2, .Net 1.1 SP1, VS 2003]
Code sample:
PrintPreviewDialog dlgPreview = new PrintPreviewDialog();
try
{
dlgPreview.Document = m_printDoc;
dlgPreview.ShowDialog(this);
}
catch(Win32Exception ex)
{
// inform the user of the problem
MessageBox.Show(ex.Message, "Printing", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
Exception Text:
System.ComponentModel.Win32Exception: The operation was canceled by the user
at System.Windows.Forms.PrintControllerWithStatusDialog.OnStartPrint
(PrintDocument document, PrintEventArgs e)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at System.Windows.Forms.PrintPreviewDialog.ToolBarClick(Object source,
ToolBarButtonClickEventArgs eventargs)
at System.Windows.Forms.ToolBar.OnButtonClick(ToolBarButtonClickEventArgs
e)
at System.Windows.Forms.ToolBar.WmReflectCommand(Message& m)
at System.Windows.Forms.ToolBar.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
the user selects print from the toolbar, and the current printer settings are
set to print to a file, a "Print to File" dialog asks them to enter a
filename. If at this point they press Cancel, they get an unhandled
exception (see below). What is strange is that I have a catch for the
exception, and all seems OK when debugging, but it is not handled when the
end user does this.
Any ideas why the exception is not caught?
[XP Pro SP2, .Net 1.1 SP1, VS 2003]
Code sample:
PrintPreviewDialog dlgPreview = new PrintPreviewDialog();
try
{
dlgPreview.Document = m_printDoc;
dlgPreview.ShowDialog(this);
}
catch(Win32Exception ex)
{
// inform the user of the problem
MessageBox.Show(ex.Message, "Printing", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
Exception Text:
System.ComponentModel.Win32Exception: The operation was canceled by the user
at System.Windows.Forms.PrintControllerWithStatusDialog.OnStartPrint
(PrintDocument document, PrintEventArgs e)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at System.Windows.Forms.PrintPreviewDialog.ToolBarClick(Object source,
ToolBarButtonClickEventArgs eventargs)
at System.Windows.Forms.ToolBar.OnButtonClick(ToolBarButtonClickEventArgs
e)
at System.Windows.Forms.ToolBar.WmReflectCommand(Message& m)
at System.Windows.Forms.ToolBar.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)