获取单击事件中按钮的 ID/名称.网络 [英] Get the ID/Name of a button in a click event. VB.NET

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

问题描述

我在 VB.NET 中有一个事件可以同时处理多个按钮点击.我需要知道选择中的哪个按钮启动了事件.任何想法如何做到这一点?我的代码如下:

I have an event in VB.NET to handle several button clicks at once. I need to know which button from the selection kicked off the event. Any ideas how to do this? My code is below:

Private Sub Answer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnswer1.Click, btnAnswer2.Click, btnAnswer3.Click, btnAnswer4.Click
    'output button ID that caused event
End Sub

我试过 sender.Id、e.Id、sender.name、e.name.他们都没有工作

I've tried sender.Id, e.Id, sender.name, e.name. None of them work

推荐答案

您必须将发件人强制转换为预期的对象类型.

You have to cast the sender to the object type expected.

 Dim btn As Button = CType(sender, Button)

然后你就可以访问你需要的东西了.

Then you can access what you need.

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

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