發布時間:2020-08-06 09:09 作者:獨孤劍 閱讀:913
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsFormsApp3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void myUserControl_UserControlBtnClicked(object sender, EventArgs e) { MessageBox.Show("用戶點擊"); } } /// <summary> /// 自定義控件 /// </summary> public partial class MyUserControl : UserControl { // 定義委托 public delegate void BtnClickHandle(object sender, EventArgs e); // 定義事件 public event BtnClickHandle UserControlBtnClicked; private void UserControl1_Click(object sender, EventArgs e) { if (UserControlBtnClicked != null) UserControlBtnClicked(sender, new EventArgs());//把按鈕自身作為參數傳遞 } } }
微信打賞, 微信掃一掃
支付寶打賞, 支付寶掃一掃
如果文章對您有幫助,歡迎給作者打賞