首页 > 其他 > 详细

Event 事件(最简单实用)

时间:2019-09-20 17:31:32      阅读:102      评论:0      收藏:0      [点我收藏+]
public partial class Form1 : Form
    {
        /// <summary>
        /// 定义事件
        /// </summary>
        public event EventHandler TestEvent;

        public Form1()
        {
            InitializeComponent();

            //事件绑定方法
            TestEvent+=new EventHandler(TestClass_TestEvent);
        }

        public void Test()
        {
            ///触发事件
            TestEvent(this, new EventArgs());
        }
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TestClass_TestEvent(object sender, EventArgs e)
        {
            MessageBox.Show("时间绑定的方法执行");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Test();
        }

 

Event 事件(最简单实用)

原文:https://www.cnblogs.com/yuanshuo/p/11558447.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!