| VB.NETですがサンプルです。
C#2008なら似たようなことは出来ると思います。
Private m_act As Action = Nothing
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If m_act IsNot Nothing Then
m_act()
End If
m_act = Nothing
Label1.Text = "Button1_Click"
End Sub
Private Sub TextBox1_Enter(sender As Object, e As System.EventArgs) Handles TextBox1.Enter
If m_act IsNot Nothing Then
m_act()
End If
m_act = Nothing
Label1.Text = ""
End Sub
Private Sub TextBox2_Enter(sender As Object, e As System.EventArgs) Handles TextBox2.Enter
If m_act IsNot Nothing Then
m_act()
End If
m_act = Nothing
Label1.Text = ""
End Sub
Private Sub TextBox1_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
If TextBox1.Text = "1" Then
MessageBox.Show("TextBox1_Validating Cancel", "TextBox1_Validating")
e.Cancel = True
Else
m_act = Sub()
MessageBox.Show("TextBox1_Validating Accepted", "TextBox1_Validating")
End Sub
End If
End Sub |