gkket 发表于 2021-9-20 16:04:39

Winform 自定义控件, 自定义事件, 委托事件

Winform 自定义控件, 自定义事件, 委托事件
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 myUserControl1_TestClick(object sender, EventArgs e)
      {
            MessageBox.Show("用户点击2");
      }
    }

    public partial class MyUserControl : UserControl
    {
      public MyUserControl()
      {
            // 注册事件
            this.Click += new System.EventHandler(this.MyUserControl_Click);
      }

      /// <summary>
      /// 自定义事件
      /// </summary>
      public event System.EventHandler TestClick;

      /// <summary>
      /// 单击事件
      /// </summary>
      /// <param name="sender"></param>
      /// <param name="e"></param>
      private void MyUserControl_Click(object sender, EventArgs e)
      {
            if (TestClick != null)
                TestClick(sender, e);
      }
    }
}



十文 发表于 2021-9-20 16:53:34

感恩无私的分享与奉献 :)

李红 发表于 2021-9-20 17:00:11

这个类目最活跃了!赞一个!

hide001 发表于 2025-11-12 17:09:11

谁懂啊!这内容我能循环看十遍

淡然_q31Nx 发表于 2025-11-12 17:20:55

赞同 + 10086,完全说出了我的想法!

C.W.Yi-소위 发表于 2025-11-12 17:28:59

这波分析到位,逻辑满分!

电小二_ZVl8n 发表于 2025-11-12 18:22:29

这逻辑绝了,分析得太到位了吧

damaoyou 发表于 2025-11-12 19:41:47

蹲一波同款,有没有姐妹 / 兄弟推荐?

阿飞 发表于 2025-11-12 20:17:39

内容太顶了!疯狂点赞,已默默收藏~

LOL09710 发表于 2025-11-12 20:20:23

楼主辛苦啦,期待下一篇分享
页: [1] 2 3
查看完整版本: Winform 自定义控件, 自定义事件, 委托事件