Hi
How do I cancel an event in a class where that event is setup in
another derived class. See example below.
Thanks
All our winforms are derived from one of our own classes, BaseForm.
This form does things like setup event handlers on each control so that
when you set focus to an edit box it selects the text.
// The base form that all our forms are derived from (abridged)
public class BaseForm : System.Windows.Forms.Form
{
public void Control_OnEnter(object sender, System.EventArgs e)
{
Control c = (Control)sender;
if (c is System.Windows.Forms.TextBox)
{
System.Windows.Forms.TextBox e =
(System.Windows.Forms.TextBox)c;
e.SelectAll();
}
private void SetControlEvents()
{
foreach (Control c in control.Controls)
{
// for all controls
c.Enter += new System.EventHandler(this.Control_OnEnter);
}
}
// on form load call SetControlEvents
}
Now we have another form that is derived from BaseForm. That form
contains a TextBox (myControl). In this class I want to somehow cancel
the event associated with myControl.
public class BaseForm : MyForm
{
myControl.Enter -= new System.EventHandler(Control_OnEnter(myControl,
null));// This gives the compiler error 'Method name expected'
myControl.Enter -= new System.EventHandler(Control_OnEnter);// This
compiles but Control_OnEnter in the base class is still called????
}