111,125
社区成员
发帖
与我相关
我的任务
分享using System;
using System.Windows.Forms;
using System.Drawing;
public class FlashTrackBar : Control {
// The event does not have any data, so EventHandler is adequate
// as the event delegate.
private EventHandler onValueChanged;
// Define the event member using the event keyword.
// In this case, for efficiency, the event is defined
// using the event property construct.
public event EventHandler ValueChanged {
add {
onValueChanged += value;
}
remove {
onValueChanged -= value;
}
}
// The protected method that raises the ValueChanged
// event when the value has actually
// changed. Derived controls can override this method.
protected virtual void OnValueChanged(EventArgs e) {
if (ValueChanged != null) {
ValueChanged(this, e);
}
}
}
public event EventHandler ValueChanged;就足够了。if (onValueChanged != null)
{
onValueChanged(this, e);
}private static readonly EventHandler onValueChanged;
public event EventHandler ValueChanged
{
add
{
base.Events.AddHandler(onValueChanged, value);
}
remove
{
base.Events.RemoveHandler(onValueChanged, value);
}
}
protected virtual void OnValueChanged(EventArgs e)
{
EventHandler handler = (EventHandler) base.Events[onValueChanged];
if (handler != null)
{
handler(this, e);
}
}