GcFunctionKey/GcClassicFunctionKeyのイベントで印刷ダイアログを表示させる場合にマウスクリックで表示するとファンクションボタンにフォーカスが残る

文書番号 : 32238     文書種別 : 不具合     登録日 : 2012/04/06     最終更新日 : 2012/04/06
文書を印刷する
対象製品
PlusPak for Windows Forms 6.0J
状況
回避方法あり
詳細
印刷ダイアログを GcFunctionKey/GcClassicFunctionKeyコントロールの FunctionKeyDown/FunctionKeyPressイベントで表示させた場合、ファンクションボタンの押下では印刷ダイアログが表示されて正常に動作しますが、マウスクリックで表示させるとファンクションボタンにフォーカスが残って一度目のマウスクリックが動作しません。

【再現コード】
[Visual Basic]
    Private Sub GcFunctionKey1_FunctionKeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles GcFunctionKey1.FunctionKeyDown
        If e.KeyCode = Keys.F3 Then
            PrintDialog1.ShowDialog()
        End If
    End Sub

    Private Sub GcClassicFunctionKey1_FunctionKeyPress(sender As System.Object, e As GrapeCity.Win.Bars.FunctionKeyPressEventArgs) Handles GcClassicFunctionKey1.FunctionKeyPress
        If e.Key = GrapeCity.Win.Bars.ButtonKeys.F3 Then
            PrintDialog1.ShowDialog()
        End If
    End Sub

[C#]
    private void gcFunctionKey1_FunctionKeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.F3)
        {
            printDialog1.ShowDialog();
        }
    }

    private void gcClassicFunctionKey1_FunctionKeyPress(object sender, GrapeCity.Win.Bars.FunctionKeyPressEventArgs e)
    {
        if (e.Key == GrapeCity.Win.Bars.ButtonKeys.F3)
        {
            printDialog1.ShowDialog();
        }
    }
回避方法
PrintDialogの表示を非同期に実行することで、現象を回避することが可能です。

[Visual Basic]
    Private Sub GcFunctionKey1_FunctionKeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles GcFunctionKey1.FunctionKeyDown
        If e.KeyCode = Keys.F3 Then
            'PrintDialog1.ShowDialog()
            ' 印刷ダイアログの表示を非同期で行います。
            Me.BeginInvoke(New DoShowPrintDialog(AddressOf DoShowDialog))
            e.Handled = True
        End If
    End Sub

    Private Sub GcClassicFunctionKey1_FunctionKeyPress(sender As System.Object, e As GrapeCity.Win.Bars.FunctionKeyPressEventArgs) Handles GcClassicFunctionKey1.FunctionKeyPress
        If e.Key = GrapeCity.Win.Bars.ButtonKeys.F3 Then
            'PrintDialog1.ShowDialog()
            ' 印刷ダイアログの表示を非同期で行います。
            Me.BeginInvoke(New DoShowPrintDialog(AddressOf DoShowDialog))
            e.Handled = True
        End If
    End Sub

    ' Delegate
    Public Delegate Sub DoShowPrintDialog()
    Private Sub DoShowDialog()
        ' 印刷ダイアログを表示します。
        PrintDialog1.ShowDialog()
    End Sub

[C#]
    private void gcFunctionKey1_FunctionKeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.F3)
        {
            //printDialog1.ShowDialog();
            // 印刷ダイアログの表示を非同期で行います。
            this.BeginInvoke(new DoShowPrintDialog(DoShowDialog));
            e.Handled = true;
        }
    }

    private void gcClassicFunctionKey1_FunctionKeyPress(object sender, GrapeCity.Win.Bars.FunctionKeyPressEventArgs e)
    {
        if (e.Key == GrapeCity.Win.Bars.ButtonKeys.F3)
        {
            //printDialog1.ShowDialog();
            // 印刷ダイアログの表示を非同期で行います。
            this.BeginInvoke(new DoShowPrintDialog(DoShowDialog));
            e.Handled = true;
        }
    }

    // delegate
    public delegate void DoShowPrintDialog();
    private void DoShowDialog()
    {
        // 印刷ダイアログを表示します。
        printDialog1.ShowDialog();
    }