Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Checking for handlers for in-built events

15 views
Skip to first unread message

Larry Lard

unread,
Jul 13, 2005, 7:36:12 AM7/13/05
to

I know that when I define my own class with an event, eg

Public Class Foo
Public Event Bar
...

behind the scenes VB creates a hidden (from IntelliSense) delegate
class BarEventHandler and an instance of that class BarEvent; and that
I can look at BarEvent.GetInvocationList to see who is watching for
this event.

That's all OK.

But now I have a (Windows Forms) Control, which has a TextChanged
event, and I want to see who's hooked up to this event. There doesn't
seem to be a TextChangedEvent (fair enough, can't ask VB.NET to create
this for everything it encounters). So how can I get the invocation
list?

(I went over to the C# group and looked for similar questions, since
they never get auto-generated stuff. But I found only this question
being asked, and no answers)

Thanks,

--
Larry Lard
Replies to group please

Jay B. Harlow [MVP - Outlook]

unread,
Jul 13, 2005, 10:02:51 AM7/13/05
to
Larry,

| But now I have a (Windows Forms) Control, which has a TextChanged
| event, and I want to see who's hooked up to this event. There doesn't
| seem to be a TextChangedEvent (fair enough, can't ask VB.NET to create
| this for everything it encounters). So how can I get the invocation
| list?
Short answer: You don't as that is an implemention detail of the Control
class, relying on implementation detail of another class breaks
Encapsulation. Encapsulation is one of the major tenants of Object Oriented
programming.


Long answer: Most components, inheriting from
System.ComponentModel.Component, store their invocation list "by key" in
Component.Events. The "key" (again being an implementation detail) is known
only to the specific class that defines the event. For detail on the Events
property see:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcomponentmodelcomponentclasseventstopic.asp

For details on using System.ComponentModel.EventHandlerList (what the Events
property returns) see:

http://weblogs.asp.net/justin_rogers/archive/2004/09/22/232834.aspx

For a writeup of how to use it in VB.NET 2005 see:

http://msdn2.microsoft.com/library/yt1k2w4e(en-us,vs.80).aspx


NOTE: Current versions of VB.NET is not able to define the AddHandler &
RemoveHandler methods needed by Events to actually use the Events property,
VS.NET 2005 (due out late in 2005) will be able to use them. C# currently
can define add & remove methods for events...


Hope this helps
Jay

"Larry Lard" <larr...@hotmail.com> wrote in message
news:1121254572.4...@z14g2000cwz.googlegroups.com...

0 new messages