yangyin
2024-10-25 1e65c49ba929103e79d87322ca1a3573c2b532e2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
 
namespace Microsoft.Windows.Forms
{
    public partial class Sprite
    {
        /// <summary>
        /// 状态改变事件索引标记
        /// </summary>
        private static readonly object EVENT_STATE_CHANGED = new object();
 
        private State m_State = State.Normal;
        /// <summary>
        /// 按钮状态
        /// </summary>
        public State State
        {
            get
            {
                return this.m_State;
            }
            set
            {
                if (value != this.m_State)
                {
                    this.m_State = value;
                    this.Feedback();
                    this.OnStateChanged(EventArgs.Empty);
                }
            }
        }
 
        /// <summary>
        /// 按钮状态改变后发生
        /// </summary>
        public event EventHandler StateChanged
        {
            add { this.Events.AddHandler(EVENT_STATE_CHANGED, value); }
            remove { this.Events.RemoveHandler(EVENT_STATE_CHANGED, value); }
        }
 
        /// <summary>
        /// 按钮状态改变事件函数
        /// </summary>
        /// <param name="e">数据</param>
        protected virtual void OnStateChanged(EventArgs e)
        {
            EventHandler handler = this.Events[EVENT_STATE_CHANGED] as EventHandler;
            if (handler != null)
                handler(this, e);
        }
    }
}