Forum Discussion
We get around this by dynamically capturing the X,Y coordinates from the desktop. Click on the item or location you want to drag from and grab the X, Y coordinates (relative to the desktop).
ax = Sys["Desktop"]["MouseX"]; ay = Sys["Desktop"]["MouseY"];
Then click on the item or location you want to drag to and grab the X, Y coordinates (relative to the desktop).
bx = Sys["Desktop"]["MouseX"]; by = Sys["Desktop"]["MouseY"];
Calculate the differences.
XDiff = bx-ax YDiff = by-ay
Then perform the drag operation (from coordinates 50, 35 in the grid control sample below).
myGrid["Drag"](50, 35, XDiff, YDiff, skAlt)
Good luck!
Yeah.
I think what you actually mean is you don't want to use hard-coded co-ordinates throughout.
Which is fine.
But you have to use co-ordinates to tell it how far to move something. That's the nature of drag and drop and there is no way round that. But, as mentioned above, you can do everything relative to the objects starting point, and all the information can be captured and calculated at run time. The only thing you have to add in to the mix is how far (X and Y distances, rather than co-ordinates) the object has to move, and then factor that into your working at run time.
I have a generic "drag this object" (which is designed to only work with certain object types on certain screens in my application where drag and drop is required). Everything is calculated by the function. In the input data, the user simply has to specify which object they want to move, and how far they want to move it. The function then finds the object and works out all the rest of the numbers itself.
Not that tricky really.