码迷,mamicode.com
首页 > 其他好文 > 详细

简易delegate委托

时间:2020-07-11 12:44:43      阅读:68      评论:0      收藏:0      [点我收藏+]

标签:name   oid   总数   ndt   void   eve   dev   ntc   hang   

#region 委托
        /// <summary>
        /// 日志
        /// </summary>
        /// <param name="s"></param>
        private delegate void MyAddLog(string str);
        private static event MyAddLog AddLog;

        private void EventAddLog(string msg)
        {
            tb_msg.AppendText(DateTime.Now.ToString("HH:mm:ss") + " " + msg + " \r\n");
        }
        /// <summary>
        /// 监听总数
        /// </summary>
        /// <param name="num"></param>
        private delegate void MyDeviceCount(int num);
        private static event MyDeviceCount DeviceCountChange;

        private void EventDeviceCount(int num)
        {
            label_jianting_count.Text = num.ToString();
        }
        #endregion

        private void Form1_Load(object sender, EventArgs e)
        {
            CheckForIllegalCrossThreadCalls = false;
            //绑定委托
            AddLog += EventAddLog;
            DeviceCountChange += EventDeviceCount;
        }

 

简易delegate委托

标签:name   oid   总数   ndt   void   eve   dev   ntc   hang   

原文地址:https://www.cnblogs.com/OleRookie/p/13283118.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!