진박사의 일상

[C#/Winform] 변수값 변경 EventHandler 본문

프로그래밍

[C#/Winform] 변수값 변경 EventHandler

진박사. 2021. 5. 16. 19:28
public int Index
        {
            get { return this.index; }
            set
            {
                this.index = value;
                OnValueChanged(null);
            }
        }

[Category("Action")]
[Description("변수값이 변경되었을 시 실행")]
public event EventHandler ValueChanged;

protected virtual void OnValueChanged(EventArgs e)
{
	if (ValueChanged != null)
       ValueChanged(this, e);
}

index값이 증가할 때마다 이벤트 호출을 해야할 필요가 있었는데 이렇게 하면 된다고