using System; namespace Microsoft.Windows.Forms { public partial class Sprite { /// /// 状态改变事件索引标记 /// private static readonly object EVENT_STATE_CHANGED = new object(); private State m_State = State.Normal; /// /// 按钮状态 /// public State State { get { return this.m_State; } set { if (value != this.m_State) { this.m_State = value; this.Feedback(); this.OnStateChanged(EventArgs.Empty); } } } /// /// 按钮状态改变后发生 /// public event EventHandler StateChanged { add { this.Events.AddHandler(EVENT_STATE_CHANGED, value); } remove { this.Events.RemoveHandler(EVENT_STATE_CHANGED, value); } } /// /// 按钮状态改变事件函数 /// /// 数据 protected virtual void OnStateChanged(EventArgs e) { EventHandler handler = this.Events[EVENT_STATE_CHANGED] as EventHandler; if (handler != null) handler(this, e); } } }