List of events for a control

  • Thread starter Thread starter VJ
  • Start date Start date
V

VJ

Is there a known way to check programatically the List of events that are
attached to a control at runtime. Say i need to know if Click event is
attached or not for a button?

VJ
 
Hi VJ,

When you look in the right button box in top of the IDE for the left
selected control you see all the visible direct usable events.

What you can do as well is looking in the class where the event derives
from, for a control that is forever control what holds the click event,
which means that for almost every control that is available (however you
have to check because by instance in the picturebox it is disabled or maybe
it is in some other controls overrided in another way).

I hope this helps?

Cor
 
* "VJ said:
Is there a known way to check programatically the List of events that are
attached to a control at runtime. Say i need to know if Click event is
attached or not for a button?

Are you referring to the number of handlers attached to an event?

\\\
Public Module Program
Public Sub Main()
Dim c As New FooBar()
AddHandler c.Foo, AddressOf Goo
c.AddSampleHandler()
c.AddSampleHandler()
Console.WriteLine( _
"Anzahl der Handler für Foo: {0}", _
c.NumberOfFooHandlers _
)
RemoveHandler c.Foo, AddressOf Goo
Console.Read()
End Sub

Private Sub Goo()
End Sub
End Module

Public Class FooBar
Public Event Foo()

Public ReadOnly Property NumberOfFooHandlers() As Integer
Get
If FooEvent Is Nothing Then
Return 0
Else
Return FooEvent.GetInvocationList().Length
End If
End Get
End Property

Public Sub AddSampleHandler()
AddHandler Foo, AddressOf Moo
End Sub

Private Sub Moo()
End Sub
End Class
///
 
Cool, do you know where the documentation is for the event (there seems to
be a variable FooEvent that is being created by dot.net).

Lloyd Sheen
 
Back
Top