如何在vb.net中获取事件名称?

前端之家收集整理的这篇文章主要介绍了如何在vb.net中获取事件名称?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这里有一个特定过程中的两个处理程序,然后是如何获取已执行的事件处理程序.

例如

Private Sub TextBox1_Events(ByVal sender As System.Object,ByVal e As System.EventArgs)     Handles TextBox1.TextChanged,TextBox1.GotFocus

End Sub

如何获得发生的事件.

解决方法

有可能使用StackTrace(可能是一种更好的方式,我不确定……).请尝试以下代码.

Private Sub TextBox1_Events(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles TextBox1.TextChanged,TextBox1.GotFocus

        Dim s As New StackTrace(True)

        For Each f As StackFrame In s.GetFrames
            Debug.WriteLine(f.GetMethod.Name)
        Next

    End Sub

当文本框获得焦点时,将写入以下内容

TextBox1_Events

OnGotFocus

OnGotFocus

WmSetFocus

Ect…….

当它是文本改变事件的时候

TextBox1_Events

OnTextChanged

OnTextChanged

Ect….

我相信你可以用这个来写一些东西来做你需要的东西.但我完全同意其他人不同的处理程序更好.

猜你在找的VB相关文章