Drag and Drop image

furjaw

Member
Joined
Jun 10, 2006
Messages
17
Programming Experience
Beginner
Visual Basic 2005 Express Edition:
I need to drag and drop an image from one PictureBox to another PictureBox where:
1) the image is visible while being dragged
2) the image can be dropped at any location within the target PictureBox
3) the image can be rotated within the target PictureBox
 
Last edited:
(1) is a simple matter of creating a custom cursor image and setting this when drag operation occurs. There is an example project at Planet Source Code showing how to do this: "drag & drop (custom cursors)" http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=3855&lngWId=10

(2) is basically also very easy, detect the mouse location when drop occurs and draw the image being dragged at this location of the image currently displaying. What makes this not basic is your requirement (3).

(3) also complicates step 2, you have to maintain state of each graphical object, ie: what image, what location (+image size=bounding rectangle) and what angle rotated. This can be done by creating a class and instantiate it for each new object, you also need a collection or array to hold these instances - this is the collection you draw when necessary, it will hold all information you need to draw everything at its place. At last you need a user interface to operate the collection, provide the necessary code logic to let user select and rotate a specific graphical object within the visible image.

An example is you have dragged and thus drawn 3 images at three different locations. When user mouse down a location point at the image you check each of the 3 objects to see if that point is within its rectangle (it's called a hittest), if that is the case consider that object selected and draw some markers that will give the user the visuals needed to see that it is selected and possibly rotate it.
 
jo0ls at xtremevbtalk.com wrote a program that does it all!
1) Transparent backround on dragged objects.
2) See object as it is being dragged.
3) Rotate object.
4) Nudge object.
5) Delete object.
6) Drag multiple objects.
7) Drag multiple copies of an object.

8) Redrag objects.

9) Drag objects of any size
Wow!
<http://www.xtremevbtalk.com/showthread.php?t=265584&goto=newpost>
 
An excellent example, furjaw, thanks for the link! :)
 
Back
Top