Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dragging around an image

Status
Not open for further replies.

tibberous

Programmer
Nov 2, 2006
8
US
I have a picture that I want the user to be able to drag anywhere on the form. I was thinking this was just a property somewhere, but after hours of goggling, all I was able to find is a site that wants to sell me the code!

Anyone know how to just freely drag an object?

Is there a way to drag an object that is bound within a square region?
 
Apparently, it is not as easy as it sounds. I found an article at BCBJournal.com from January 2005 but it is in the member's area. BTW, BCB Journal is an excellent e-mag so joining would be helpful. If I get a chance, I'll look the article over.


James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Well, I got it working, but not with anything built in. Basically I use the mouse down event to store X, Y and Sender in global variables. Then I use the mouse move event to keep setting the new X and Y of the panel, with the mouse up event setting Sender to NULL. Works fine, might be the only way to do it, pretty easy to add a bounding rect too.
 
That's pretty much how the article described how to do it, too.


James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
i remember trying to do this ages ago and i used the borland inbuilt way but the way you've done it actually sounds alot better then the Borland "inbuilt" way, there is a few properties and things you can do to enable dragging on an object. ive actually dug up the old code for it, and its a bit of a cheat, the method is you set the controls dragmode property to dmAutomatic, then in the forms "OnDragOver" event function you insert the code:
((TImage*)(Source))->Left = X;
((TImage*)(Source))->Top = Y;
which is the bit that kinda defeats the point of an automatic drag! However this does mean that now any control that you set to dmAutomatic will be dragable and i think it allows the OnStartDrag, OnEndDrag functions to be used which can be handy. but if you try to drag it onto another picture it wont let you unless that picture is unenabled, so it can be alot more fussy and alot more annoying but it might be fun to have a play with it just to laugh at its inferioterty! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top