By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,552 Members | 905 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,552 IT Pros & Developers. It's quick & easy.

List of events for a control

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
Nov 20 '05 #2

P: n/a
You can use reflection to look at the list of events that a control has. Use Type.GetEvents().

Rgds,
Anand
VB.NET MVP
http://www.dotnetindia.com

"VJ" wrote:
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

Nov 20 '05 #3

P: n/a
* "VJ" <vi********@yahoo.com> scripsit:
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
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #4

P: n/a
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

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OI*************@TK2MSFTNGP11.phx.gbl...
* "VJ" <vi********@yahoo.com> scripsit:
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
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.