Drag Picturebox

I

Ikey

I am trying to allow a user to drag a Picturebox control around the
form and drop it in a new location.

Currently, I was trying to use the following:

Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove

If e.Button() = Windows.Forms.MouseButtons.Left Then
sender.Location = e.Location
Debug.Print(sender.name.ToString &
sender.location.ToString)
sender.Refresh()
Me.Refresh()
End If

End Sub

Originally, I didn't have the Refresh calls in there but added them
because the object appears to flicker between 2 locations. I then
added the Debug.Print to see the following:

PictureBox1{X=65,Y=46}
PictureBox1{X=77,Y=28}
PictureBox1{X=65,Y=46}
PictureBox1{X=77,Y=28}
PictureBox1{X=65,Y=46}
PictureBox1{X=77,Y=28}
PictureBox1{X=65,Y=46}
PictureBox1{X=77,Y=28}

If I press the left button down and move the PictureBox even a little
bit and hold the mouse still, the box flashes between the 2 locations.
Is there something I missing or a better way to accomplish this?

Thanks,
Michael
 
G

Guest

dont use sender, use the picturebox name because "sender" is only a copy of
the picturebox, since it has the "byval" tag to it, so set the picturebox
name to the location and it should work
 
A

Armin Zingler

iwdu15 said:
dont use sender, use the picturebox name because "sender" is only a
copy of the picturebox, since it has the "byval" tag to it, so set
the picturebox name to the location and it should work

No, Sender does point to the Picturebox. The argument is ByVal, thus it does
contain a copy, but only a copy of the reference. A Picturebox is a
reference type.


Armin
 
G

Guest

Using the API bitblt, you can copy the picture box from the picture box
graphics object into a bitmap then create a cursor from the bitmap when the
mouse down event is pressed. When the Mouse up event occurs, you can then
reposition the picture box to the new coordinates..it works great.
 

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