Jump to content
Xtreme .Net Talk

Recommended Posts

  • Leaders
Posted

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?

  • *Gurus*
Posted

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

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...