请问:EventArgs怎么传递非Empty参数??
protected virtual void OnChanged()
{
if (Changed != null)
{
Changed(this, EventArgs.Empty);
}
}
EventArgs如果传递非Empty参数,怎么实现??
--------------------编程问答-------------------- EventArgs没办法传递参数。
要传递参数,就从EventArgs派生一个。
看看你的参数,是不是触发事件的对象的属性
如果是的话,需要的参数可以通过Sender变量访问 --------------------编程问答--------------------
protected virtual void OnChanged()
{
if (Changed != null)
{
Changed(this, new EventArgs());
}
}
--------------------编程问答-------------------- MouseEventArgs KeyPressEventArgs 这些事件参数都是从EventArgs派生的 --------------------编程问答--------------------
new EventArgs() 和 EventArgs.Empty 是一样的吧,都表示空参数
并且感觉用EventArgs.Empty 还好一点,整个引用程序只有一个对象,
用new EventArgs()会重复的分配 释放内存 --------------------编程问答-------------------- change(this,new EventArgs()); --------------------编程问答-------------------- private string _text = “”;
public delegate void ChangedEventHandler(object sender, EventArgs e);
public event ChangedEventHandler Changed;
// 用以触发Change事件
protected virtual void OnChanged(EventArgs e)
{
if (this.Changed != null)
this.Changed(this, e);
}
public string Text
{
get { return this._text; }
set
{
this._text = value;
// 文本改变时触发Change事件
this.OnChanged(new EventArgs());
}
--------------------编程问答-------------------- 直接派生一个空的就可以了
补充:.NET技术 , C#