handling events of objects stored in array

Hi,

I have an array of objects. These objects have events that needed to be handled in the Form class. But, I am facing difficulty in declaring WithEvents for these objects, as these are not at the class level.

Eg:

I need to do something like

I declare array of that class at class level
When the button is pressed, then instantiate the objects in the array "WithEvents".
I need to handle events in the form raised by each object within the array

How to achieve this. Please explain. Thanks in advance.

Regards,
Noorul

[552 byte] By [NoorulAhmed] at [2007-12-28]
# 1
oops, sorry wrong thread
NoorulAhmed at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

i would handle this situation like this:

handle each event that i need to implement.

Public Sub Test()

Dim forms(5) As Object

'Add object and so on...

For Each f As Object In forms

AddHandler CType(f, Form).FormClosing, AddressOf Form_Closing

Next

End Sub

Private Sub Form_Closing(ByVal s As Object, ByVal e As FormClosingEventArgs)

'do something

End Sub

hrubesh at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
Moved thread to VB group. Please re-relocate if this is not the right place
LouisDavidson at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...