在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Drawing; 5 using System.Data; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 10 namespace UserControls 11 { 12 public partial class UserControl1 : UserControl 13 { 14 public delegate void MyDelegate(object sender, EventArgs e);//建立委托 15 public MyDelegate myEven_click; 16 public UserControl1() 17 { 18 InitializeComponent(); 19 button1.Click += new EventHandler(button1_Click); //绑定委托事件 20 } 21 22 private void button1_Click(object sender, EventArgs e) 23 { 24 if (myEven_click != null) 25 { 26 myEven_click(sender, e); 27 } 28 } 29 } 30 } 1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 10 namespace 自定义控件的点击事件 11 { 12 public partial class Form1 : Form 13 { 14 public Form1() 15 { 16 InitializeComponent(); 17 } 18 19 private void Form1_Load(object sender, EventArgs e) 20 { 21 userControl11.myEven_click += new UserControls.UserControl1.MyDelegate(fuzhi);//把事件绑定到自定义的委托上 22 } 23 public void fuzhi(object sender ,EventArgs e) 24 { 25 label1.Text = "456"; 26 } 27 } 28 }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论