Drag and drop multiple canvas controls together

I’ve made an app where the user can move individual canvas controls on a window using drag and drop. It works well.
I would like the user to be able to select multiple items and move them as a group either by holding down cmd/ctrl and selecting or dragging the mouse across a group of them, as commonly found in many apps.
Is this possible with Xojo.

Have you tried ?

What I would do (not tested, design only):
I draw mu own focus rings.
When the User Command-Click (the first time) in a Canvas:
I draw a Focus Ring,
I add its reference to an Array,
(a click on a Canvas already selected will do the reverse: remove the custom Focus ring / the entry in the Array)

When the user move one of the custom “selected” Canvasses…, and move them to a target, I copy the images from all Canvas and place them in the target Canvas.

Of course, you have to deal with where to place each Canvas, etc. I cannot help for that since I never saw that case. (in a Paint area; in a Draw area, the user place them later).

HTH / gives ideas.

Hello Craig ?

Are-you there ? Still searching ideas ? Got what you want ?

Thanks for the suggestion. I’m still trying your idea but haven’t been able to get it to work as yet.

What part gaves troubles ?
(x,y for each canvas Pictures in the Target Canvas ?)

Did you read the Drag and Drop part of the Documentation ?
There may be interesting information there for this case.

You can place each Canvas image at side by side (then in the next Row if needed), then allow the user to click in one dropped image (at a time) to change its x,y values.

No one drop in with ideas ?

1 Like

Something to consider…

Instead of dragging entire canvases, make a single canvas with classes that represent the individual draggable things. Each would have its own “Paint” method which you would call from the canvas Paint event using a Graphics.Clip of just the area it represents.



But a “trouble” setting the x,y at Paint time still exists (unless each individual image always goes to its own location), a click to set x,y is needed…

Not really. What you do is keep track of where each of its children are with Rects. Then when you have a click, you can loop through and figure out which Rects contain the click. You’ll need an array of integer to keep track of the selected children’s indexes.

When dragging items, you just move the coordinates of everything that’s selected and have it refresh periodically so you can see things move.