Martijn Mulder wrote:
Documentation suggests that I should make a call to the base-class method
for some methods. When I try to do so for the class below, I get wrong
results. What is the correct way to make a call to the base class for an
event like this?
//class Form
class Form:System.Windows.Forms.Form
{
//constructor
Form()
{
MouseEnter+=OnMouseEnter;
}
//OnMouseEnter
void OnMouseEnter(System.Object a,System.EventArgs b)
{
base.OnMouseEnter(b);
}
//Main
[System.STAThread]
static void Main()
{
System.Windows.Forms.Application.Run(new Form());
}
}
If you are handling this throug events as you are, then there is no need to
call the base class as that has already happened by the time you get to your
event handler. If instead of using event handlers you had overriden the
OnMouseEnter method of the base class, then in your override you would want
to make sure you called the base. That would like similar to as follows:
//class Form
class Form:System.Windows.Forms.Form
{
//constructor
Form()
{
}
//OnMouseEnter
protected override void OnMouseEnter(System.EventArgs b)
{
base.OnMouseEnter(b);
}
//Main
[System.STAThread]
static void Main()
{
System.Windows.Forms.Application.Run(new Form());
}
}
--
Tom Porterfield