Question on events

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

Guest

Hi All,
when you chain an event eg tb.Enter+= ; Is it possible to ensure I will get the first bite at the event
and also is it possible to refuse access to this event lower down the chain.

hope my question makes sense.
thank you.
 
It didn't make sense to me, but I'm not so smart anymore since I stuck
my fork in the power outlet...

What chain are you talking about?
What "bite" are you talking about?

Are you asking that in the event handling method if you will get the
first character in the textbox?
And are you also asking if it is possible to prevent other objects
which can see your textbox object, from also handling the same event?

I feel like a monkey without a banana in this thread.
 
Hello,

I don't think you can stop the execution of the other methods once the event
has been fired.

Note that doing "tb.Enter = new ..." with delele all the previous methods
that where
registered with the event.
 
Is it possible to ensure I will get the first bite at the event

No. Even if you could know for sure the order that the handlers will be
called by the event delegate, you should never depend upon that.

If you are subclassing, then you should override the OnEnter() method
rather than subscribing to the Enter event, for exactly this reason.
However, if your event subscriber is not a subclass of the class that
defines the Enter event, then there are no guarantees about the order
in which you'll be called.
it possible to refuse access to this event lower down the chain

Technically, no, but a similar mechanism does exist in .NET. Take a
look at KeyPressEventArgs: event arguments that contain a boolean
(Handled) that indicates "I've already handled this... don't bother
with it." In this case, however, it's not events "lower down the chain"
that are being advised that the event has been "handled," but rather
the default behaviour in the defining class that kicks in _after_ the
event is raised and only if Handled comes back from all event handlers
as false.
 
Back
Top