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!

image dragging

Status
Not open for further replies.

exodus300

Programmer
Mar 22, 2002
262
AU
Hmmm haven't been here for a while...

I'm playing around with a little proggy that has a kind of board (ie a panel) on which images can be dragged around. I worked out how to create the images at run-time but how do I achieve the dragging them around bit?

Thx for ur help. I haven't been here for a while (because I have not done much [any] programming for a while) so I hope you guys can help me. Thanks!

[Thanks in advance|Hope I helped you]
Exodus300
[pc3]
 
Well first, place a Timage on the form, use this as your canvas instead of Panel. The load your images into TBitmaps like so:

TBitmap Background;
BackGround->LoadFromFile("Img.bmp")

Next load any images to the canvas of the image (same as loading them to a panel), and load them to whatever location using the top left hand corner of the of the image (X, Y)

TImage->Canvas->Draw(X, Y, BackGround);

Then to move them you use the OnMouseDown method in TImage, this passes in the XY co-ordinates of the mouse, so with a few if statements or a switch, you can use these coords to check which image you have clicked on, then you can use offsets of these mouse co-ordintes to be able to alter the position of the image (the Images X,Y pos)

be sure to repaint the Image->Canvas otherwise you will get trails.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top