-2
我用我的图形对象自定义事件通知的对象的变化:自定义事件初始化问题
public class OnLabelWidthChangedEventArgs : EventArgs
{
private float _width;
public float Width
{
get { return _width; }
set { _width = value; }
}
public OnLabelWidthChangedEventArgs(float widthParam) : base()
{
Width = widthParam;
}
}
这是激发此事件的对象:
public class DisplayLabel : DisplayTextObject
{
public event EventHandler<OnLabelWidthChangedEventArgs > OnLabelSizeChanged;
public DisplayLabel(ScreenView _screenParam, IXapGraphicObject obj) : base(_screenParam, obj)
{
l = new Label();
SetSize();
}
public override void SetSize()
{
Width = w;
Height = h;
if(OnLabelWidthChanged != null)
OnLabelSizeChanged.Invoke(this, new OnLabelWidthChangedEventArgs(w)); // OnLabelSizeChanged is null
}
的OnLabelSizeChanged
总是空,怎么我可以初始化它吗?
我有一个代表,而不是自定义事件的工作解决方案:
public event OnWidthChanged WidthChanged = delegate { };
,但我想知道如何解决这个问题,使用自定义事件。
谢谢你的帮助。
你工作的解决方案也是一个自定义事件。 – Servy
查看https://www.google.com.br/search?q=C%23+custom+events – Tony