how can i create this group shape or a container shape

Mar 15, 2012 at 11:22 AM

nshape can create group shape,but if grouped,all shape can't to move.

or,Create a shape as a container,and create a child shape drag into this container , and can be moved

 

can see this demo: http://files.cnblogs.com/try/demo.swf

Coordinator
Mar 15, 2012 at 2:04 PM

Out of the box, NShape has no shapes that behave exactly the same like the shapes shown in your demo video.
But you can rearrange grouped shapes:

  • Select the group
  • Click on the child shape you want to move
  • The shape's handles are displayed and the outlines of the other shapes in the group become gray.
  • Now, you can move the child shape

If you want to implement the shown behavior yourself, you have to write your own container shape:

  • Derive a ContainerShapeAggregation from ShapeAggregation or GroupShapeAggregation
  • Override the NotifyChildMoving/NotifyChildMoved methods and restrict the children's movements to the bounds of the Owner.
  • Derive your shape from Shape and implement the interface IShapeGroup:
      public class ShapeGroup : Shape, IShapeGroup
    You can take a look at the implementation of class ShapeShape for the details.
  • Use your ContainerShapeAggregation as Children collection.
  • If you want to prevent the shapes to move out of the owner's bounds, you have to derive a set of shapes from the appropriate base classes.

 

Best regards,
Kurt