473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 2225
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Chua Wen Ching | last post by:
Hi there. My maths is kind of bad, and i really need to guides. Just say i am allowed to create mouseevents in a picturebox. There is a prefix image1 (x = 10, y = 10), image2 (x = 10, y =...
0
by: Trythat | last post by:
How can I drag and drop a image from Internet Explorer (IE or Mozilla etc) to my PictureBox, I can drag a image from a window, whereby I use a string which contains the filename, but this doesn't...
1
by: Boni | last post by:
Dear all, I need to drag node from a tree view on a picturebox. I made following: AllowDrop in picturebox. Handle picturebox drop events. But those events never happen. My feeling is that...
0
by: pamelafluente | last post by:
Hi, I have a PictureBox on a form. I wish to drag the image exposed by the PictureBox through the property "image" to a window of Windows Explorer. The new file will have a name assigned by the...
2
by: TarheelsFan | last post by:
I am having problems with drag and drop into a listview. I am able to drag and drop items from within the listview, as well as drag items from the listview and drop into a picturebox. However, I...
1
by: Steven Garrad | last post by:
Hi All, I have a pictureBox control inside of a panel control. The pictureBox is larger than the panel control and I have the panel control set true for AutoScroll so the panel displays scrolling...
0
by: Truevision .Net | last post by:
Hi, I have a problem with drag and drop functionality when it comes to dropping pictures from sources like for example internet explorer and the webbrowser control. Dragging and dropping from...
1
by: Steve Bottoms | last post by:
Hi, all! Using VB .Net 2k5 under Vista Business... I'm trying to put together a very basic drag-and-drop for file copying, and can't seem to get DragDrop events (Form, PictureBox, TextBox, etc)...
1
by: mohanavel | last post by:
Hi, My problem is. I have two user control that holds one label and one Picture box. Say user Controls A and B. A - has DoDragDrop(this, DragDropEffects.Copy) method. its called...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.