How to detect which event is being handled from multiple events?

核能气质少年 提交于 2019-12-12 01:34:48

问题


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

来源:https://stackoverflow.com/questions/26642031/how-to-detect-which-event-is-being-handled-from-multiple-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!