PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
Drag Picturebox
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
Drag Picturebox
![]() |
Drag Picturebox |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#3 |
|
Guest
Posts: n/a
|
"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 |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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 > > |
|
|
|
#5 |
|
Guest
Posts: n/a
|
Thanks Both
|
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

