获取触发事件的按钮的名称 [英] Get the name of the button that triggered the event

查看:153
本文介绍了获取触发事件的按钮的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个处理多个按钮的点击事件的事件处理程序:

I have an event handler that handles the click event of multiple buttons:

Private Sub primeHandler(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _2s.Click, _3s.Click, _4s.Click, _5s.Click, _6s.Click

End Sub

_2s,_3s等都是按钮。
现在我需要一种方式来确定哪个按钮触发了事件,并且还将按钮的名称作为字符串。有什么办法吗感谢

_2s, _3s, etc are all buttons. Now I need a way to determine which button triggered the event and also get the button's name as string. Any way to do that? Thanks

推荐答案

您可以投递发件人键入 并访问Name属性。

You can cast sender to type Button and access the Name property.

Private Sub primeHandler(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _2s.Click, _3s.Click, _4s.Click, _5s.Click, _6s.Click
    Dim myButton As Button = CType(sender, Button)
    Dim myName As String = myButton.Name
End Sub

这篇关于获取触发事件的按钮的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆