Dynamic control events
-
Hello Could some of you, great people, please help me? I have a array of controls and I would like to get the events. Here is the code: Dim pic(10) as system.windows.forms.picturebox For a=0 to 10 pic(a)=new system.windows.forms.picturebox ' the rest of the properties me.panel1.controls.add(pic(a)) next How can I catch the events of the 'pic' controls? Thanks
-
Hello Could some of you, great people, please help me? I have a array of controls and I would like to get the events. Here is the code: Dim pic(10) as system.windows.forms.picturebox For a=0 to 10 pic(a)=new system.windows.forms.picturebox ' the rest of the properties me.panel1.controls.add(pic(a)) next How can I catch the events of the 'pic' controls? Thanks
You have to write up the events of the PictureBox controls yourself using AddHandler[^].
Dim myPicBox As New PictureBox
AddHandler myPicBox.Click, AddressOf PicBoxClick
.
.
.
Private Sub PicBoxClick(ByVal sender As Object, ByVal e As System.EventArgs)
...
End SubDon't forget to use RemoveHandler to disconnect the handler before you destroy the picturebox. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Hello Could some of you, great people, please help me? I have a array of controls and I would like to get the events. Here is the code: Dim pic(10) as system.windows.forms.picturebox For a=0 to 10 pic(a)=new system.windows.forms.picturebox ' the rest of the properties me.panel1.controls.add(pic(a)) next How can I catch the events of the 'pic' controls? Thanks
You have used an array for the picture boxes which I don't suggest you to do that because you must have Addhandler or Eventhandler statements to control the event's of picture boxes. According to your code, you should have one mutual eventhandler procedure which will run all the picture boxes. Focus on Addhandler and Eventhandler statements to get more information. Here is an example from MSDN : Sub TestEvents() Dim Obj As New Class1 ' Associate an event handler with an event. AddHandler Obj.Ev_Event, AddressOf EventHandler ' Call the method to raise the event. Obj.CauseSomeEvent() ' Stop handling events. RemoveHandler Obj.Ev_Event, AddressOf EventHandler ' This event will not be handled. Obj.CauseSomeEvent() End Sub Sub EventHandler() ' Handle the event. MsgBox("EventHandler caught event.") End Sub Public Class Class1 ' Declare an event. Public Event Ev_Event() Sub CauseSomeEvent() ' Raise an event. RaiseEvent Ev_Event() End Sub End Class :))
-
Hello Could some of you, great people, please help me? I have a array of controls and I would like to get the events. Here is the code: Dim pic(10) as system.windows.forms.picturebox For a=0 to 10 pic(a)=new system.windows.forms.picturebox ' the rest of the properties me.panel1.controls.add(pic(a)) next How can I catch the events of the 'pic' controls? Thanks