标签:个数 tar send show 匹配 gate btn 语法糖 .sh
//public delegate void EventHandler(object sender, EventArgs e); public partial class Form1 : Form { //public event EventHandler Click; public Form1() { InitializeComponent(); Button btn = new Button(); btn.Click += new EventHandler(btn_Click); btn.Click += konglong_Click; btn.Click += new EventHandler(btnOk_Click); btn.Click += delegate { MessageBox.Show("这是一个匿名的无参的方法"); }; this.Controls.Add(btn); // 2.0时代这种写法是利用了编译器的合理推断,语法糖 //手动添加一个自定义的方法 this.btnOk.Click += new EventHandler(btnZjTj); this.btnOk.Click += konglong_Click; ////没参数的匿名函数 //this.btnOk.Click += delegate //{ // MessageBox.Show("吃掉它"); //}; ////有参数的匿名函数,如果有参那就一定要和当前事件所修饰的委托的签名要求的参数类型和个数相匹配 this.btnOk.Click += delegate(object sender, EventArgs e) { //Button btnme = (Button)sender; MessageBox.Show((sender as Button).Text + ":吃掉它"); }; } private void btnZjTj(object sender, EventArgs e) { MessageBox.Show("这是我自已写的方法啊,好牛X了"); } private void btnOk_Click(object sender, EventArgs e) { MessageBox.Show("自然产生"); } private void btn_Click(object sender, EventArgs e) { MessageBox.Show("人为添加"); } private void konglong_Click(object sender, EventArgs e) { MessageBox.Show("恐龙"); } void Invoke(EventHandler f) { MessageBox.Show("我就不调用,气死牙不齐"); } private void button1_Click(object sender, EventArgs e) { MessageBox.Show("你看OK不OK"); } }
标签:个数 tar send show 匹配 gate btn 语法糖 .sh
原文地址:https://www.cnblogs.com/myBlogOu/p/9938439.html