C#实现某一属性值变化时触发事件 Form1_changeEvent是对应的事件

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int i = 0;
        private void Form1_Load(object sender, EventArgs e)
        {
            changeEvent += Form1_changeEvent;
        }
        void Form1_changeEvent(string value)
        {
            this.richTextBox1.Invoke(new Action(() => { this.richTextBox1.AppendText("当前lable的值为" + value+" "); }));
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Temp = i + "";
            label1.Text = Temp;
            i++;
        }
        public delegate void ChangeDelegate(string value);
        public event ChangeDelegate changeEvent;
        public string _temp;
        public string Temp
        {
            get { return _temp; }
            set
            {
                if (_temp != value)
                {
                    changeEvent(value);
                }
                _temp = value;
            }
        }
    }
}
自动驱动未来
原文地址:https://www.cnblogs.com/rb-huang/p/13791521.html