ControlCollection with Events

  • Thread starter Thread starter Brian Burgess
  • Start date Start date
B

Brian Burgess

Hi all,

Anyone know of a way to declare a ControlCollection with Events in VB.NET?

Thanks in advance..

-BB
 
WithEvents declaration was used in VB6 to attach to existing events that
object has defined. In VB.NET it is replaced by .AddHandler method on the
event delegate:
AddHandler MyForm.Load, AddressOf MyHandler

This will not help you if the class you are thinking about does not expose
events. To the best of my knowledge, control collection does not. If you
want to attach event handlers to an event for every control in collection,
walk it using for each statement:

for each ctl as Control in myControlCollection
AddHandler ctl.GotFocus, AddressOf MyHandler
next ctl

Sub MyHandler(sender as Object, e as EventArgs)
Dim ctl as Control = CType(sender, Control)
...
 
Back
Top