Multiple Event Handler Hierarchy

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

Hopefully this is a simple question: I have a Form with a Button and that
button has a "Click" event handler. The button is marked as protected (not
private). If I inherit from the form and assign the button another Click
event handler in the derived class, will the base class handler always
execute first, or will this be an unpredictable behavior?

Thanks.
 
* "=?Utf-8?B?U3RldmU=?= said:
Hopefully this is a simple question: I have a Form with a Button and that
button has a "Click" event handler. The button is marked as protected (not
private). If I inherit from the form and assign the button another Click
event handler in the derived class, will the base class handler always
execute first,

AFAIK, yes, except you manipulate the list of handlers.
 
Herfried K. Wagner said:
AFAIK, yes, except you manipulate the list of handlers.

I would say no. AFAIK, the order in which the event handlers are invoked
is not guaranteed. In the real world though, the base class will likely be
invoked first (since it was added first) but personally I wouldn't rely on
it

/claes
 
Thanks very much to both of you.

Herfried, I read the link you referenced and I agree with your
interpretation, but I think I may alleviate the risk -- I might mark the
buttons as private and just bubble the event. I plan to use this base class
heavily and I don't need any extra pain. :)

Thanks again.
 
Claes,

* "Claes Bergefall said:
:-)

Yep, you're correct. Haven't read the C# spec. too much.
:-)

I would assume it applies to VB aswell (my language of choice)?

I assume that applies to VB.NET (which is my language of choice too) as
well.
 
Back
Top