Simple Drag Drop

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math Topics]   [Library]   [Utilities]

Search

 

Search DelphiForFun.org only

Support DFF

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

 

If you shop at Amazon anyway,  consider using this link. We receive a few cents from each purchase.   Thanks.

In Association with Amazon.com

 

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

 

Search DelphiForFun.org only

 

 

 

I received this email the other day:

I want to develop an application which generates a random, three part code using three colours. These colours can be repeated during the sequence. The main point im struggling with is that i want the user to drag and drop the colours into a guess sequence.

This is basically the main features of the program and i wondered if you can give me some feedback on how to code it.

I decided to start with the drag-drop part just to see how simple it could be accomplished.  Even I was surprised by the answer - only two lines of code to accomplish the "guess" part of the above program description!

Here they are:

  1. In a OnDragOver event exit for the target spaces, we need to set "Accept := true;" to tell the systems that it is OK to drop the color here.
  2. In the OnDragDrop event exit we must set the target's color to the dragged object's color.  In our case, we are dragging one of several colored  TShapes to  a target TShape so the 2nd line of code is "Tshape(sender).brush.color := Tshape(source).brush.Color;"

The other key step is change DragMode property of the objects to be dragged from dmManual to dmAutomatic.

That's it. 

Download Source Code

Created: March 23, 2004

Modified: November 07, 2008

 

 

  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright © 2000-2009, Gary Darby    All rights reserved.