私は、オブジェクトの変更を通知するために私のグラフィックオブジェクト上のカスタムイベントを使用します。カスタムイベントの初期化の問題
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
はどのように、常にnullであります私はそれを初期化できますか?
私の代わりにカスタムイベントの代表者との作業溶液持っている:
public event OnWidthChanged WidthChanged = delegate { };
を私はカスタムイベントで、この問題を解決する方法を知っているように思います。
ありがとうございました。
あなたのワーキングソリューションは、カスタムイベントです。 – Servy
https://www.google.com.br/search?q=C%23+custom+events – Tony