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();
                }
            }
        }
    }
}

 

posted @ 2016-01-15 21:56  虚-染D  阅读(292)  评论(0编辑  收藏  举报