按钮发件人 [英] button sender

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

问题描述

Hiii全部
我在每个按钮的onclick中有3个按钮,它将执行特定功能.
该功能将是相同的,只不过其中一行会显示不同的结果.
我可以在该功能中询问点击是否来自哪个按钮吗?
有什么帮助吗?
Thanks

Hiii all
i have 3 buttons in the onclick of each one it will go to execute aspecific function.
that function will be the same except one line that will differ in disply the result.
can i ask in that function if the click came from which button?
any help, please?
thanks

推荐答案

您可以将按钮ID传递给该函数.

You can pass the button id to the function.

void MyFunc(string buttonID)
{
    //insert function code here
}

private void btnSubmit_Click(object sender, EventArgs e)
{
    Button b = (Button)sender;
    MyFunc(b.Name);
}


您可以使用Button的CommandName属性来指定从哪个按钮引发事件. 每个按钮使用不同的命令名称.
希望这可以..
You can use CommandName property of Button to specify from which button the event has been raised..
use different command names for each button.
Hope this will work..


嘿,
您可以在函数中添加参数.并在调用函数时将按钮的名称作为参数发送.
例如
hey,
you can add an argument in the function. and send the name of the button as argument while calling the function.
e.g.
function Showdata(string buttonName)
{
if(buttonName=="btn1")
{
//do stuff
}
if(buttonName=="btn2")
{
//do stuff
}
}

if(buttonName=="btn3")
{
//do stuff
}



祝你好运
问候
Ahsan Sarfraz

如果信息有用,请不要忘记将其标记为已回答.谢谢



Best of luck
regards
Ahsan Sarfraz

Dont forget to mark as answered if info was useful.Thanks


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

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