C# Windows Forms Print Dialog box click OK twice to respond

Posted by sbartlett007 on Stack Overflow See other posts from Stack Overflow or by sbartlett007
Published on 2010-04-15T21:06:36Z Indexed on 2010/04/15 21:13 UTC
Read the original article Hit count: 340

Filed under:
|
|

I'm using Visual Studio 2008, .net Framework 3.5 for a Windows forms client-server app that I'm working on. There is a weird bug when I run the program and try to print. The print dialog box opens, but I have to click the OK button twice for it to work. After the second click it works fine, no errors. When I put a breakpoint on: if (result == DialogResult.OK) , the breakpoint doesn't trigger until the second click. Here is the code:

private void tbPrint_Click(object sender, EventArgs e)
{
    try
    {
        printDialog1.Document = pDoc;

        DialogResult result = printDialog1.ShowDialog();

        if (result == DialogResult.OK)
        {
            pDoc.PrinterSettings.PrinterName = printDialog1.PrinterSettings.PrinterName;
            pDoc.Print();
        }
        ...

This is driving me crazy, and I can't see anything else that would interfere with it.

© Stack Overflow or respective owner

Related posts about c#

Related posts about printing