Multiple Event Handler Hierarchy

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.
 
H

Herfried K. Wagner [MVP]

* "=?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.
 
C

Claes Bergefall

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
 
G

Guest

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.
 
H

Herfried K. Wagner [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top