How to determen the object ?

J

John Devlon

Hi,

I've created a form and on the fly several pictureboxes are created...

Dim x As Integer = 0
Dim myCollection As List(Of PictureBox) = New List(Of PictureBox)
Dim Location As Integer = 50

For x = 0 To 5
Dim myBox As PictureBox = New PictureBox
myBox.SetBounds(50, Location * x, 34, 34)
myBox.BackColor = Color.Black
myBox.BringToFront()
myBox.AllowDrop = True
Me.Controls.Add(myBox)
myCollection.Add(myBox)
myBox = Nothing
Next

I would like to use drag and drop to put pictures in the pictureboxes and a
function like this ...

Private Sub picureBox_DragDrop(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles PictureBox3.DragDrop

End Sub

But what if I created the pictureboxes on the fly ? I can't use "handles
PictureBox" ...

I propably have the use the sender but how ?

John
 
S

Steve Long

Exactly! You can do what Seth said and use the AddHandler method each time
you add a picturebox on the fly and point it to, maybe, the same
pictureBox_DragDrop method. Inside your method, you can do a Select Case or
something to detect which Picturebox called the method maybe something like
this:

Dim pic as PictureBox = sender ' you could also convert it yourself
using the Convert method or a DirectCast call.

Select Case pic.Name
Case "PictureBox1"
Case "PictureBox2"
End Select

Get the pattern here?

HTH
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top