且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-11-24 16:30:04

使用 StackTrace 是可能的(我不确定可能是更好的方法......).试试下面的代码.

It is possible using the StackTrace (could be a better way I'm not sure...). Try the following code.

 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

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

When the text box gets focus the following is written:

TextBox1_Events

TextBox1_Events

OnGotFocus

OnGotFocus

WmSetFocus

等等…….

当它是文本更改事件时

TextBox1_Events

TextBox1_Events

OnTextChanged

OnTextChanged

OnTextChanged

OnTextChanged

等等……

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

I’m sure you could write something using this to do what you need. But i fully agree with the other guys separate handlers is better.