K
Kenneth Bohman
Armin wrote on the 1st of Jan as a reply to Lorne Smith
"The designer creates the default procedure for events. Event procedures are
usually not Public Overridable. IMO, you should not change the signature in
the base class. If you want an overridable sub handling the Click, add an
Overridable OnButtonClick procedure called in the event handler of the base
class. In the derived class, override OnButtonClick".
Question 1:
Can anyone give an example (VB.NET if possible) on how to do that? I can't
find any. Not even the MSDE example for OnClick is about OnClick. I've got a
copule of books on Windows Forms (many of the good) and loads of online
articles, the authors avoid going into inherited forms, which is a pity,
since quite many questions in this discussion group seem to be about just
that.
Question 2:
I'm successfully using override, but now I get confused:
Lorne Smith writes: "when I put code in the sub, it was executed twice when
I ran the form. Now I realised this is because both the base form and the
inherited form are handling the event".
WHY does both the base form and the inherited form execute the event? I
thought override meant that the overriding method executes INSTEAD of the
overridden, not that both are executed. Why would I use the override keyword
if I want both to execute? But clearly Lorne is right in that both are
executed. I've considered that an oddity, but it is by-design then.
Kind Regards,
Kenneth Bohman
"The designer creates the default procedure for events. Event procedures are
usually not Public Overridable. IMO, you should not change the signature in
the base class. If you want an overridable sub handling the Click, add an
Overridable OnButtonClick procedure called in the event handler of the base
class. In the derived class, override OnButtonClick".
Question 1:
Can anyone give an example (VB.NET if possible) on how to do that? I can't
find any. Not even the MSDE example for OnClick is about OnClick. I've got a
copule of books on Windows Forms (many of the good) and loads of online
articles, the authors avoid going into inherited forms, which is a pity,
since quite many questions in this discussion group seem to be about just
that.
Question 2:
I'm successfully using override, but now I get confused:
Lorne Smith writes: "when I put code in the sub, it was executed twice when
I ran the form. Now I realised this is because both the base form and the
inherited form are handling the event".
WHY does both the base form and the inherited form execute the event? I
thought override meant that the overriding method executes INSTEAD of the
overridden, not that both are executed. Why would I use the override keyword
if I want both to execute? But clearly Lorne is right in that both are
executed. I've considered that an oddity, but it is by-design then.
Kind Regards,
Kenneth Bohman