Search code examples
c#printingprintdialog

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


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.


Solution

  • Maybe it is an issue similar to this one: http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/681a50b4-4ae3-407a-a747-87fb3eb427fd