C#基础练习(时间的三连击)

Form1的后台代码:

namespace _07事件的三连击
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
           // utc.Mdl += DoSth;
           utc.Mdl+=new MyDelegate(utc_Mdl);//给用户控件创建了一个事件
        }

       //这个事件里执行的方法
        void utc_Mdl()  
        {
            MessageBox.Show("哈哈,有区别,委托可以=,+=,-=,可以直接调用");
        }
    }
}

自定义控件UserThreeClick的后台代码:

namespace _07事件的三连击
{
    public delegate void MyDelegate();//先定义一个委托
    public partial class UserThreeClick : UserControl
    {
        public UserThreeClick()
        {
            InitializeComponent();
        }


        private int num = 0;
        public event MyDelegate Mdl;//在委托前加event关键字,定义一个事件
        private void btn_Click(object sender, EventArgs e)
        {
            num++;
            if (num==3)
            {
                num = 0;
                if (this.Mdl!=null)
                {
                    this.Mdl();
                }
            }
        }
    }
}

 

相关文章:

  • 2021-10-11
  • 2022-12-23
  • 2021-12-14
  • 2021-08-11
  • 2021-12-23
  • 2022-02-02
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-24
  • 2022-01-15
  • 2021-05-17
  • 2022-12-23
  • 2022-12-23
  • 2021-06-11
相关资源
相似解决方案