Groups are shapes, which aggregate other shapes. Groups are represented by the NGroup class, which derives from NShape class. You can construct a group from any types of shapes - including other groups. Groups are by default treated as 2D shapes. Groups support drill down selection, which means that you can select the shapes contained in a group.
Groups are created similarly to composite shapes. The difference is that groups can contain only shapes. The following example creates a group, which contains three shapes:
C# |
Copy Code
|
---|---|
NGroup group = new NGroup(); // create ellipse NEllipseShape ellipse = new NEllipseShape(0, 0, 100, 100); ellipse.Text = "Ellipse"; group.Shapes.AddChild(ellipse); // create rectangle NRectangleShape rect = new NRectangleShape(150, 0, 100, 100); rect.Text = "Rectangle"; group.Shapes.AddChild(rect); // create line NLineShape line = new NLineShape(0, 150, 100, 250); line.Text = "Line"; group.Shapes.AddChild(line); // update the model bounds of the group group.UpdateModelBounds(); |
Visual Basic |
Copy Code
|
---|---|
Dim group As New NGroup() ' create ellipse Dim ellipse As New NEllipseShape(0, 0, 100, 100) ellipse.Text = "Ellipse" group.Shapes.AddChild(ellipse) ' create rectangle Dim rect As New NRectangleShape(150, 0, 100, 100) rect.Text = "Rectangle" group.Shapes.AddChild(rect) ' create line Dim line As New NLineShape(0, 150, 100, 250) line.Text = "Line" group.Shapes.AddChild(line) ' update the model bounds of the group group.UpdateModelBounds() |
It is important to remember that you must call the UpdateModelBounds method of the group once you have finished adding shapes to it. This is necessary in order for the group to adopt the bounds of the shapes it contains (see Models for more information about aggregate models bounds).
Since the user can select the shapes contained in a group, this allows him/her to delete all shapes of a group - i.e. make an empty group.
You can protect a group from becoming empty with the help of the CanBeEmpty property. If this property is set to false the user will not be able to delete the last shape of a group.
You can also instruct groups to automatically destroy themselves when the become empty. This is specified by the AutoDestroy property. If this property is set to true the group will automatically destroy itself when its last child is removed.