本文介绍了如何在 vb.net 中获取事件名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里在一个特定的过程中有两个处理程序,然后如何获取执行了哪个事件处理程序.

Here there are two handlers in a particular procedure then how to get which event handler has performed.

例如

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

End Sub

如何获取发生了哪个事件.

how to get which event has occured.

推荐答案

使用 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

OnGotFocus

OnGotFocus

WmSetFocus

等等…….

当它是文本更改事件时

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.

这篇关于如何在 vb.net 中获取事件名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 06:19