问题描述:

My problem:

I need to detect what event (e.g. TextChanged) is currently being handled from within the handling Sub that's handling multiple objects/events. I cannot find examples online (though this may be a terminological issue). I already know how to detect the object but I do not know how to detect the event.

To reproduce:

  1. In Visual Studio, in design mode, drag two text boxes onto a fresh form.
  2. Use the following as is:

Code:

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

相关阅读:
Top