自动创建具有不同工作方式的按钮 [英] Automatic create buttons with different working

查看:85
本文介绍了自动创建具有不同工作方式的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道通过编码来创建按钮,但是dnt知道如何为按钮添加不同的功能.我的代码是:

I know to create buttons through coding but dnt know how to add different functionality to it. my code is :

for(int i=0;i<3;i++)
{                       Button bz = new Button();
                         bz.Height = 50;
                         bz.Width = 50;
                         bz.ToolTip = fname1;
                         gg.Children.Add(bz);
} // gg is uniformGrid


它现在创建3个按钮bt,我希望每个按钮都应执行不同的任务,例如,如果我单击第一个按钮,它应该添加两个编号,如果我单击其他按钮,那么它将做减法操作...以及如何给每个按钮起名字按钮.. ??

提前感谢

pls dnt给msdn.microsoft链接带来了很多帮助..


it create 3 buttons bt now i want each of this should perform different task like if i click first button it should add two no.s and if i click other then it will do subtraction... And how to give name to each of these buttons..??

thanks in advance

pls dnt give msdn.microsoft links they dnt help much..

推荐答案



您可以创建匿名函数并将点击事件与所有按钮相关联.

您可以使用不同的按钮来决定要做什么.

或者您也可以关联您的功能,例如



you can create anonymous function and associate click event with your all buttons.

you can decide what you want to do with different buttons.

or you can associate your function like

btn.Click += new System.EventHandler(this.myFunction);



希望这对您有帮助,

谢谢
-Amit



Hope this will help you,

Thanks
-Amit


btnHeader.Click += delegate { Functin_name() }


这样,您可以创建一个事件.如果我单击按钮,它将来到btnHeader.Click并执行括号内的功能.

希望对您有帮助:)


In this way you can create an event.If i click on the button it will come to btnHeader.Click and execute the functions present inside the bracket .

Hope this will help you :)


这篇关于自动创建具有不同工作方式的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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