手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#通过委托调用Button单击事件的方法
C#通过委托调用Button单击事件的方法
摘要:这里介绍通过委托取消Button事件switch-case的方法。需要注意的是,事先要按顺序在各个Button的Tag属性中设置0、1、2、...

这里介绍通过委托取消Button事件switch-case的方法。需要注意的是,事先要按顺序在各个Button的Tag属性中设置0、1、2、3……等序号,其作用请详看代码。

/*定义委托*/ public delegate 类型或viod MethodDelegate(参数1, 参数2); private void buttonC_Click(object sender, EventArgs e) { Button button = (Button)sender; /*向委托添加方法*/ MethodDelegate methodDelegate = 你的方法1; methodDelegate +=你的方法2; methodDelegate +=你的方法3; ………. /*转换成数组*/ Delegate[] delegates = methodDelegate.GetInvocationList(); /*根据button.Tag中序号选择委托列表数组中相应方法*/ MethodDelegate method = (MethodDelegate)delegates[Convert.ToInt16(button.Tag)]; /*执行*/ 类型 i = method(参数1, 参数2); } Private 类型或viod 你的方法1 (参数1, 参数2) { ………. } Private 类型或viod 你的方法2 (参数1, 参数2) { ………. } Private 类型或viod 你的方法3 (参数1, 参数2) { ………. }

以上所述就是本文的全部内容了,希望大家能够喜欢。

【C#通过委托调用Button单击事件的方法】相关文章:

C#技巧之快速删除bin和obj文件夹的方法

C# 打开电子邮件软件的具体方法

C#实现对AES加密和解密的方法

C# 获取打印机当前状态的方法

C# IP地址与整数之间转换的具体方法

C#异步调用的好处和方法分享

使用SmtpClient发送邮件的方法

C#访问应用程序配置文件的方法

C#使用DllImport调用非托管的代码的方法

C#中一些你可能没用过的调试窗口的方法

精品推荐
分类导航