B
bill
I got an exception when trying to start a PrintPreviewDialog or print for a
specific network printer. The code works for other network printers. That
printer works perfectly for all other applications. The exception happens
when PrintDocument.Print() is called or PrintPreviewDialog.ShowDialog() is
called. I set a breakpoint at the event handler. I has not been called yet
when the exception happened. I did check
PrintDocument.PrinterSettings.IsValid. It was true. Does anyone know how I
can further debug this problem? Thanks for your help. Here is the exception
in my VS.NET debugger and the code:
A first chance exception of type
'System.Drawing.Printing.InvalidPrinterException' occurred in
system.drawing.dll
Additional information: Tried to access printer '\\abc\printer1' with
invalid settings
I then clicked "continue". The message appeared for three times. Then, an
error message dialog came up with
************** Exception Text **************
System.Drawing.Printing.InvalidPrinterException: Tried to access printer
'\\abc\printer1' with invalid settings.
at System.Windows.Forms.PrintPreviewControl.CalculatePageInfo()
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
==========================================================
PrintDocument pd = new PrintDocument();
pd.PrintPage +=new PrintPageEventHandler(pd_PrintPage);
pd.PrinterSettings.PrinterName = name;
if (isPrint)
{
pd.Print();
else
{
this.printPreviewDialog1.Document = pd;
this.printPreviewDialog1.ShowDialog (this);
}
specific network printer. The code works for other network printers. That
printer works perfectly for all other applications. The exception happens
when PrintDocument.Print() is called or PrintPreviewDialog.ShowDialog() is
called. I set a breakpoint at the event handler. I has not been called yet
when the exception happened. I did check
PrintDocument.PrinterSettings.IsValid. It was true. Does anyone know how I
can further debug this problem? Thanks for your help. Here is the exception
in my VS.NET debugger and the code:
A first chance exception of type
'System.Drawing.Printing.InvalidPrinterException' occurred in
system.drawing.dll
Additional information: Tried to access printer '\\abc\printer1' with
invalid settings
I then clicked "continue". The message appeared for three times. Then, an
error message dialog came up with
************** Exception Text **************
System.Drawing.Printing.InvalidPrinterException: Tried to access printer
'\\abc\printer1' with invalid settings.
at System.Windows.Forms.PrintPreviewControl.CalculatePageInfo()
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
==========================================================
PrintDocument pd = new PrintDocument();
pd.PrintPage +=new PrintPageEventHandler(pd_PrintPage);
pd.PrinterSettings.PrinterName = name;
if (isPrint)
{
pd.Print();
else
{
this.printPreviewDialog1.Document = pd;
this.printPreviewDialog1.ShowDialog (this);
}