C#外部控件调用click事件

控件A定义

  • 自定义控件中有如下click事件:
 public event EventHandler Click;
  • 自己调用click
 public void DoClick()
        {
            if (this.Click != null)
            {
                this.Click(this, new EventArgs());
            }
        }

外部control定义

  • 在control中有个A控件属性
private NavBarButton _button;
  • 定义该事件:
 this._button.Click += new EventHandler
                (
                delegate(object sender, EventArgs e)
                {
                    if (this._groupState == NavGroupState.collapse)
                        this.GroupState = NavGroupState.expand;
                    else
                        this.GroupState = NavGroupState.collapse;
                });
  • 调用事件
this._button.DoClick();

你可能感兴趣的:(c#)