码迷,mamicode.com
首页 > Windows程序 > 详细

c# 共享事件处理程序

时间:2017-10-17 17:23:16      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:返回   exception   orm   object   副本   event   添加   format   分享   

使用同一个方法来处理多个Button实例的Click事件。

1、全选所有的Button,在事件添加中的Click点击事件中添加处理函数。

技术分享

2、假如一个label控件用于显示按钮按下输出文本

3、处理函数程序

 private void OnButtonClick(object sender, EventArgs e)
        {
            Button btnClicked = (Button)sender;//强制类型转换object sender转换成Button
            label1.Text = string.Format("单击了“{0}”按钮",btnClicked .Text );
        }

//
// 摘要:
// 将指定字符串中的一个或多个格式项替换为指定对象的字符串表示形式。
//
// 参数:
// format:
// 复合格式字符串。
//
// arg0:
// 要设置格式的对象。
//
// 返回结果:
// format 的副本,其中的任何格式项均替换为 arg0 的字符串表示形式。
//
// 异常:
// T:System.ArgumentNullException:
// format 为 null。
//
// T:System.FormatException:
// format 中的格式项无效。- 或 - 格式项的索引不为零。
public static String Format(String format, object arg0);

c# 共享事件处理程序

标签:返回   exception   orm   object   副本   event   添加   format   分享   

原文地址:http://www.cnblogs.com/hjxzjp/p/7682652.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!