我需要在处理多个对象/事件的处理Sub中检测当前正在处理的事件(例如TextChanged)。我在网上找不到例子(虽然这可能是一个术语问题)。我已经知道如何检测对象,但我不知道如何检测事件。
代码:
Private Sub TextBox_CombinedEvents(sender As Object, e As EventArgs) Handles TextBox1.Enter,
TextBox2.Enter, TextBox1.TextChanged, TextBox2.TextChanged,
TextBox1.Leave, TextBox2.Leave
Dim detectedEvent as String = "?"
If detectedEvent = "Enter" Then
MessageBox.Show("Text has been entered.")
Elseif detectedEvent = "TextChanged" Then
MessageBox.Show("Text has been changed.")
Elseif detectedEvent = "Leave" Then
MessageBox.Show("Text box has been left.")
Else
MessageBox.Show("Event not detected.")
End If
End Sub