Leaders Squirm Posted April 2, 2003 Leaders Posted April 2, 2003 I'm creating a number of pictureboxes dynamically: For i = 0 To 14 pPicture = New PictureBox() cPics.Add(pPicture, CStr(i)) Me.Controls.Add(pPicture) pPicture.Width = 60 pPicture.Height = 60 pPicture.Left = (iPositions(i) Mod 4) * 60 pPicture.Top = (iPositions(i) \ 4) * 60 pPicture.Visible = True pPicture.Image = Image.FromFile("C:\EVBFpuzzle\" & CStr(i) & ".bmp") Next i All is well, the pictureboxes appear as they should. Now comes the part I'm having difficulty with. I want to have a procedure which handles the click event for all of these pictureboxes. Just one procedure. How would I go about achieving this? Quote Search the forums | Still IRCing | Be nice
*Gurus* divil Posted April 2, 2003 *Gurus* Posted April 2, 2003 Use AddHandler to bind the event to a procedure in every loop iteration: AddHandler pPicture.Click, AddressOf myProcedure Private Sub myProcedure(sender As Object, e As System.EventArgs) 'sender is the picturebox that raised the event End Sub Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
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.