Home All Groups Group Topic Archive Search About

How to determen the object ?

Author
6 Oct 2006 2:21 PM
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

Author
6 Oct 2006 2:31 PM
rowe_newsgroups
Lookup "AddHandler"

Thanks,

Seth Rowe

John Devlon wrote:
Show quoteHide quote
> 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
Author
6 Oct 2006 3:20 PM
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


Show quoteHide quote
"John Devlon" <johndev***@hotmail.com> wrote in message
news:UDtVg.115047$7V7.1364111@phobos.telenet-ops.be...
> 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
>