Denaes Posted March 21, 2005 Posted March 21, 2005 I have an array of 4-25 objects (normally) want them to raise an event at a specific time passing the information of which one they are. Say for example I just want to send another class a string containing some data. VS says I cannot declare a variable WithEvents if it's part of an Array. Is there anyther way to get around this? Quote
Leaders snarfblam Posted March 21, 2005 Leaders Posted March 21, 2005 Look up AddHandler in the Help. The Handles clause (in conjuntion with WithEvents) in VB essentially breaks down to the same thing as using AddHandler, it is just easier on the eyes. When you instantiate each object in the array, use the AddHandler statement to add the event handlers. Dim btnButtonsGalore As Button() = New Button(16) {} Sub Populate For i As Integer = 0 To btnButtonsGalore.Length() - 1 btnButtonsGalore(i) = New Button AddHandler btnButtonsGalore(i).Click, AddressOf btnButtonsGalore_Click Next i End Sub Sub btnButtonsGalore_Click(sender As Object, e As EventArgs) '... End Sub Quote [sIGPIC]e[/sIGPIC]
Denaes Posted March 22, 2005 Author Posted March 22, 2005 ok I knew there was some way to delegate this but it's been so long I was just thinking of raising events within the class itself. Let me question really quickly... AddHandler btnButtonsGalore(i).Click, AddressOf btnButtonsGalore_Click AddHandler is grabbing the event and adding it to the procedure btnButtonsGalore_Click. So this way you don't need to "hardcode" anything in advance, it just sends all those buttons' Click Event to that one procedure. That would be exactly what I was looking for. Thank you :D Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.