Search the Community
Showing results for tags 'drag'.
Found 3 results
-
I have managed to write a program which demonstrates the methods outlined in parts 1&2. I created an image component with the ability to move built in. The program appears to work perfectly and gives the end user the impression that they are dragging and dropping the image. As you can see its pretty basic but surprisingly simple. I hope that this solution addresses the problem and could be adapted and improved. The main program is included as an attachment to this post. It also includes the code necessary to create the Angord component. Unit1.pas
-
In order to move an image in Delphi 7 you do the following. 1. Program movement of image relative to the mouse. 2. Within a loop check if the image being moved overlaps an image on screen. You check each control in the componentlist and by using the PtinRect function determine if it returns a true value. If it is true then you can retrieve the name of the component underneath and thus interact with it. 3. If the function returns a true value then within the code that checks for this you write code to check if particular criteria is met. You simply use the mouse events in conjunction with the PtinRect value to determine what to do with the image/images if the criteria is met. For instance you could check if the values of a shared property in both images when added together come to a certain value i.e scoring a hand of cards. You could then write simple code to either overwrite an image or swap the images over. If the criteria is not met you write code to return the moved image back to its original starting position. The terms Drag and Drop are misleading in this case. Think of it as Move and Release. Remember you do not use any Drag and Drop functions, procedures and commands. I hope this explains the procedure/s required.
-
I may be passing on old news, if not then I have found out how to successfully drag and drop images in Delphi. You do not use the existing commands concerned with drag and drop they are only used to move text from one text control to another or drag items from windows explorer. You use the PTinRect command and program a response to the outcome. The command checks if the top left corner of a control falls inside the boundary rectangle of another control. If it does then you can identify the name of the control underneath and perform an appropriate action. You have to create your own methods depending on the outcome but this is very easy basically IF..THEN commands. It works for any control and as I discovered is the standard method used by software companies to drag and drop images. Borland/Embarcadero never told us about this. I hope this has been helpful?