Search code examples
.netbegininvoke

Print Dialog Focus Issue


I am using PrintDialog in my desktop application. When it is invoked from Button or from context menu it works fine. But when I click the tooltip button for invoking the PrintDialog, despite the printdialog window is active, I am not getting the focus on the print button. I need to click twice to get the print.

The solution I got is to use BeginInvoke with delegate to call async and now I am able to get the focus with the following code.

ShowThePrintDialog printD = new ShowThePrintDialog(p.ShowDialog); this.BeginInvoke(printD);

I want to capture the DialogResult and proceed further based on the button clicked on printdialog.

Can anybody give me an idea how to capture the DialogResult while using BeginInvoke?

Raman


Solution

  • The PrintDialog doesn't get the focus, because the toolstripbuttons Click-event doesn't finish. This can be solved by using a timer:

    private void toolStripButtonPrint1_Click(object sender, EventArgs e)
    {
        timerPrint1.Start();
    }
    
    private void timer1_Tick(object sender, EventArgs e)
    {
        timerPrint1.Stop();
        if (printDialog1.ShowDialog() == DialogResult.OK)
        {
            // do your stuf
        }
    }