>// First you must make a public EventHandler: >public event EventHandler MyClick; > >// Then, in the base button's Click EventHandler, do this: >this.OnMyClick(new EventArgs()); > >// Lastly, this raises the MyClick event: >protected virtual void OnMyClick(EventArgs e) >{ > if (MyClick != null) > MyClick(this, e); >} >>Then, in your sub-classed button, you just set up the usual delegates and EventHandlers:
>this.MyButton.MyClick += new System.EventHandler(this.MyButton_MyClickHandler); > >private void MyButton_MyClickHandler(object sender, System.EventArgs e) >{ > bool lResult = this.Login_Click(); > if (!lResult) > this.txtCompanyID.Focus(); >} >>
>public event EventHandler MyClick; >public event EventHandler MyClickDoSomething; > >private void MyBaseButton_ClickHandler(object sender, System.EventArgs e) >{ > this.OnMyClick(new EventArgs()); > this.OnMyClickDoSomething(new EventArgs()); >} >>One event actually does the default code, the other event simply raises the event.
>protected virtual void OnMyClickDoSomething(EventArgs e) >{ > if (MyClickDoSomething != null) > { > this.AuthenticateUser(); > > MyClickDoSomething(this, e); > } >} >protected virtual void OnMyClick(EventArgs e) >{ > if (MyClick != null) > { > MyClick(this, e); > } >} >>If the sub-classed button (or the button on a form) has a delegate to the MyClickDoSomething event, then the default code (your AuthenticateUser() method in your case) will be executed as usual prior to the code in the sub-classed button's event handler. However, if you don't want the default code on the control to fire, you set a delegate to the other event instead (the MyClick()) thereby enabling the sub-classed button to do some code and the default (the AuthenticateUser()) will not get done.