GcButton押下時に他コントロールのValidatingイベントが発生しないことがある

文書番号 : 37075     文書種別 : 不具合     登録日 : 2014/03/05     最終更新日 : 2014/04/23
文書を印刷する
対象製品
PlusPak for Windows Forms 7.0J
状況
修正済み
詳細
GcButton押下時に他コントロールの Validatingイベントが呼ばれた場合、その Validatingイベント内でメッセージボックスを表示すると 2回目のボタン押下時に Validatingイベントが呼び出されません。
回避方法
この問題はService Pack 2(v7.0.2014.0423)で修正されました。
不具合を修正した最新のサービスパックは、アップデートページ からダウンロードできます。

また、Validatingイベントのメッセージを表示するタイミングを変更することで現象を回避できます。

[Visuall Basic]
  Private Sub TextBox1_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
    If TextBox1.Text = "100" Then
      'MessageBox.Show("TextBox1_Validating")

      ' メッセージを表示するタイミングを変更します。
      needProcessedNULLMessage = True
      PostMessage(Me.Handle, WM_NULL, System.Runtime.InteropServices.Marshal.StringToBSTR("TextBox1_Validating"), IntPtr.Zero)

      e.Cancel = True
    End If
  End Sub

  Private Sub GcButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GcButton1.Click
    System.Diagnostics.Debug.WriteLine("GcButton1_Click")
  End Sub

  ' *** 回避コード ***
  Private needProcessedNULLMessage As Boolean = False

  <System.Runtime.InteropServices.DllImport("user32.dll", CharSet:=System.Runtime.InteropServices.CharSet.Auto)> _
  Private Shared Function PostMessage(ByVal hwnd As IntPtr, ByVal msg As Integer, ByVal wparam As IntPtr, ByVal lparam As IntPtr) As Boolean
  End Function

  Private Const WM_NULL As Integer = 0
  Protected Overloads Overrides Sub WndProc(ByRef m As Message)
    If m.Msg = WM_NULL AndAlso needProcessedNULLMessage Then
      Dim str As String = System.Runtime.InteropServices.Marshal.PtrToStringAuto(m.WParam)
      MessageBox.Show(str)
      needProcessedNULLMessage = False
    End If
    MyBase.WndProc(m)
  End Sub
  ' ******

[C#]
  private void textBox1_Validating(object sender, CancelEventArgs e)
  {
    if (textBox1.Text == "100")
    {
      //MessageBox.Show("textBox1_Validating");

      // メッセージを表示するタイミングを変更します。
      needProcessedNULLMessage = true;
      PostMessage(this.Handle, WM_NULL, System.Runtime.InteropServices.Marshal.StringToBSTR("textBox1_Validating"), IntPtr.Zero);

       e.Cancel = true;
    }
  }

  private void gcButton1_Click(object sender, EventArgs e)
  {
    System.Diagnostics.Debug.WriteLine("gcButton1_Click");
  }

  
  // *** 回避コード ***
  private bool needProcessedNULLMessage = false;

  [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
  private static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam);

  private const int WM_NULL = 0;    
  protected override void WndProc(ref Message m)
  {
    if (m.Msg == WM_NULL && needProcessedNULLMessage)
    {
      string str = System.Runtime.InteropServices.Marshal.PtrToStringAuto(m.WParam);
      MessageBox.Show(str);
      needProcessedNULLMessage = false;
    }
    base.WndProc(ref m);
  }
  // ******
キーワード
PPWI08128