Checking for handlers for in-built events

  • Thread starter Thread starter Larry Lard
  • Start date Start date
L

Larry Lard

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,
| 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/d...emcomponentmodelcomponentclasseventstopic.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



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

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

Back
Top