Home All Groups Group Topic Archive Search About
Author
2 Feb 2006 5:50 PM
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

Author
2 Feb 2006 8:22 PM
iwdu15
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
Author
2 Feb 2006 8:42 PM
Armin Zingler
"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
Author
3 Feb 2006 11:41 AM
Dennis
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


Show quoteHide quote
"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
>
>
Author
3 Feb 2006 8:29 PM
Ikey
Thanks Both