469,623 Members | 1,511 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

Drag Picturebox

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

Feb 2 '06 #1
4 2068
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
--
-iwdu15
Feb 2 '06 #2
"iwdu15" <jmmgoalsteratyahoodotcom> schrieb
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

Feb 2 '06 #3
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.
--
Dennis in Houston
"Ikey" wrote:
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

Feb 3 '06 #4
Thanks Both

Feb 3 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Chua Wen Ching | last post: by
1 post views Thread by Boni | last post: by
2 posts views Thread by TarheelsFan | last post: by
1 post views Thread by Steven Garrad | last post: by
reply views Thread by Truevision .Net | last post: by
1 post views Thread by Steve Bottoms | last post: by
1 post views Thread by mohanavel | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.