I have a customer control that inherits from System.Windows.Forms.Control. Its not the worlds most complicated control but I have a problem. I'm trying to get a count of the number of events connected to base.click. Is this possible

Thank

Al

Re: Counting Connected Event Handlers by DalePres

DalePres
Tue Feb 10 10:10:29 CST 2004

Try using GetInvocationList().Length. I don't know if it will work in your
application or not but it works in mine.

Dale

"Alec Dobbie" <Alec.Dobbie@gingerMonkey.SmartApproach.com> wrote in message
news:5DC40765-C7D0-41EA-8D84-0F95506B0A6A@microsoft.com...
> I have a customer control that inherits from System.Windows.Forms.Control.
Its not the worlds most complicated control but I have a problem. I'm
trying to get a count of the number of events connected to base.click. Is
this possible?
>
> Thanks
>
> Al



Re: Counting Connected Event Handlers by Stoitcho

Stoitcho
Tue Feb 10 11:33:35 CST 2004

Hi Alec
No, it is not posible.
To be able to do that you have to have access to the event's backup field
which is a delegate and then you can get its invocation list.
But
1) usually those fields are private
The event doesn't give you access to the delegate. Event is simply set
of accessor methods (Add, Rmove and Invoke) So you never deal directly with
the delegate.

2) One can say "The first point is not a problem we can use reflection to
get the field". The problem is that the controls comming with the framework
don't have backup fields at all. They keep mapping tables for the events and
creates dynamically delegates only for the hooked events. What are those
tables how are they organized are Windows Forms internals.

Thus, the answer is NO.
--
B\rgds
100

"Alec Dobbie" <Alec.Dobbie@gingerMonkey.SmartApproach.com> wrote in message
news:5DC40765-C7D0-41EA-8D84-0F95506B0A6A@microsoft.com...
> I have a customer control that inherits from System.Windows.Forms.Control.
Its not the worlds most complicated control but I have a problem. I'm
trying to get a count of the number of events connected to base.click. Is
this possible?
>
> Thanks
>
> Al



Re: Counting Connected Event Handlers by hirf-spam-me-here

hirf-spam-me-here
Tue Feb 10 14:31:54 CST 2004

* "=?Utf-8?B?QWxlYyBEb2JiaWU=?=" <Alec.Dobbie@gingerMonkey.SmartApproach.com> scripsit:
> I have a customer control that inherits from
> System.Windows.Forms.Control. Its not the worlds most complicated
> control but I have a problem. I'm trying to get a count of the number
> of events connected to base.click.

\\\
Public Class Main
Public Shared 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 Shared Sub Goo()
End Sub
End Class

Public Class FooBar
Public Event Foo()

Public ReadOnly Property NumberOfFooHandlers() As Integer
Get
Return FooEvent.GetInvocationList().Length
End Get
End Property

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

Private Sub Moo()
End Sub
End Class
///

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

Re: Counting Connected Event Handlers by Stoitcho

Stoitcho
Tue Feb 10 15:03:28 CST 2004

Hi Herfried,

I don't think Alec asks for that solution. Alec wants to count the event
handler of Control's Click event.
--
B\rgds
100

--
B\rgds
100
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:uFr1hWB8DHA.1504@TK2MSFTNGP12.phx.gbl...
> * "=?Utf-8?B?QWxlYyBEb2JiaWU=?="
<Alec.Dobbie@gingerMonkey.SmartApproach.com> scripsit:
> > I have a customer control that inherits from
> > System.Windows.Forms.Control. Its not the worlds most complicated
> > control but I have a problem. I'm trying to get a count of the number
> > of events connected to base.click.
>
> \\\
> Public Class Main
> Public Shared 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 Shared Sub Goo()
> End Sub
> End Class
>
> Public Class FooBar
> Public Event Foo()
>
> Public ReadOnly Property NumberOfFooHandlers() As Integer
> Get
> Return FooEvent.GetInvocationList().Length
> End Get
> End Property
>
> Public Sub AddSampleHandler()
> AddHandler Foo, AddressOf Moo
> End Sub
>
> Private Sub Moo()
> End Sub
> End Class
> ///
>
> --
> Herfried K. Wagner [MVP]
> <http://www.mvps.org/dotnet>



Re: Counting Connected Event Handlers by hirf-spam-me-here

hirf-spam-me-here
Tue Feb 10 15:18:03 CST 2004

* "Stoitcho Goutsev \(100\) [C# MVP]" <100@100.com> scripsit:
> I don't think Alec asks for that solution. Alec wants to count the event
> handler of Control's Click event.

It's only a sample.

;-)

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