简易delegate委托

#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 + " 
");
        }
        /// <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;
        }
原文地址:https://www.cnblogs.com/OleRookie/p/13283118.html