|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to determen the object ?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 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 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 >
vb 6.0 naar vb.net 2005
Need some array help. Dynamic mapping string to function creating pictureboxes on the fly WEB combobox won't fire event NullReferenceException with shared members Website local/remote login Access My.Settings from class library crash at closue msvbvm60.dll Bring my FORM to front?? |
|||||||||||||||||||||||