How to make shapes (drag and dropped) to align itself with equal spacing ?

May 4 at 6:39 PM
Hi Kurt,

I am building an industrial application, in which we are adding customized shapes each representing a unit or process flow.

My requirement is
  1. When I drag and drop a shape to template, it should start at top left corner.
  2. Adding further shapes should align itself to the right side of it's previous shape.
  3. And finally there should be equal spacing between all the shapes, If required user should be able to adjust space between them.
Can I get a clue on how to accomplish this, Your expertise in my last query was of great help.
Thanks in advance.

-Foiaz
Coordinator
May 5 at 8:13 AM
foiazh wrote:
  1. When I drag and drop a shape to template, it should start at top left corner.
  2. Adding further shapes should align itself to the right side of it's previous shape.
  3. And finally there should be equal spacing between all the shapes, If required user should be able to adjust space between them.
I assume you mean 'drag a shape to the diagram (sheet)'?
You could handle the Display component's or the Repository component's ShapesInserted event (IDisplayPresenter.ShapesInserted / IRepository.ShapesInserted)
and move the shape(s) after they were added to the display's diagram.

If you want to get an idea of the events available in NShape, start the "NShape Designer" and check out "Tools" > "NShape Event Monitor" (in the main menu). Right-click the list on the left and select "Enable all". This logs all raised events to the list on the right.

The alternative would be to derive custom Tool classes (PlanarShapeCreationTool for creating planar shapes, PointerTool for the standard manipulation tool).
The tools handle mouse and keyboard interaction with the diagram/shapes. This option requires more digging into the code but enables more options.

Hope this helps.