GroupShape

GroupShape class

Represents a group of shapes in a document.

To learn more, visit the How to Add Group Shape into a Word Document documentation article.

public class GroupShape : ShapeBase

Constructors

NameDescription
GroupShape(DocumentBase)Creates a new group shape.

Properties

NameDescription
AllowOverlap { get; set; }Gets or sets a value that specifies whether this shape can overlap other shapes.
AlternativeText { get; set; }Defines alternative text to be displayed instead of a graphic.
AnchorLocked { get; set; }Specifies whether the shape’s anchor is locked.
AspectRatioLocked { get; set; }Specifies whether the shape’s aspect ratio is locked.
BehindText { get; set; }Specifies whether the shape is below or above text.
Bottom { get; }Gets the position of the bottom edge of the containing block of the shape.
Bounds { get; set; }Gets or sets the location and size of the containing block of the shape.
BoundsInPoints { get; }Gets the location and size of the containing block of the shape in points, relative to the anchor of the topmost shape.
BoundsWithEffects { get; }Gets final extent that this shape object has after applying drawing effects. Value is measured in points.
CanHaveImage { get; }Returns true if the shape type allows the shape to have an image.
CoordOrigin { get; set; }The coordinates at the top-left corner of the containing block of this shape.
CoordSize { get; set; }The width and height of the coordinate space inside the containing block of this shape.
Count { get; }Gets the number of immediate children of this node.
CustomNodeId { get; set; }Specifies custom node identifier.
DistanceBottom { get; set; }Returns or sets the distance (in points) between the document text and the bottom edge of the shape.
DistanceLeft { get; set; }Returns or sets the distance (in points) between the document text and the left edge of the shape.
DistanceRight { get; set; }Returns or sets the distance (in points) between the document text and the right edge of the shape.
DistanceTop { get; set; }Returns or sets the distance (in points) between the document text and the top edge of the shape.
virtual Document { get; }Gets the document to which this node belongs.
Fill { get; }Gets fill formatting for the shape.
FirstChild { get; }Gets the first child of the node.
FlipOrientation { get; set; }Switches the orientation of a shape.
Font { get; }Provides access to the font formatting of this object.
Glow { get; }Gets glow formatting for the shape.
HasChildNodes { get; }Returns true if this node has any child nodes.
Height { get; set; }Gets or sets the height of the containing block of the shape.
HeightRelative { get; set; }Gets or sets the value that represents the percentage of shape’s relative height.
Hidden { get; set; }Gets or sets a boolean value indicating whether the shape is visible.
HorizontalAlignment { get; set; }Specifies how the shape is positioned horizontally.
HRef { get; set; }Gets or sets the full hyperlink address for a shape.
override IsComposite { get; }Returns true as this node can have child nodes.
IsDecorative { get; set; }Gets or sets the flag that specifies whether the shape is decorative in the document.
IsDeleteRevision { get; }Returns true if this object was deleted in Microsoft Word while change tracking was enabled.
IsGroup { get; }Returns true if this is a group shape.
IsHorizontalRule { get; }Returns true if this shape is a horizontal rule.
IsImage { get; }Returns true if this shape is an image shape.
IsInline { get; }A quick way to determine if this shape is positioned inline with text.
IsInsertRevision { get; }Returns true if this object was inserted in Microsoft Word while change tracking was enabled.
IsLayoutInCell { get; set; }Gets or sets a flag indicating whether the shape is displayed inside a table or outside of it.
IsMoveFromRevision { get; }Returns true if this object was moved (deleted) in Microsoft Word while change tracking was enabled.
IsMoveToRevision { get; }Returns true if this object was moved (inserted) in Microsoft Word while change tracking was enabled.
IsSignatureLine { get; }Indicates that shape is a SignatureLine.
IsTopLevel { get; }Returns true if this shape is not a child of a group shape.
IsWordArt { get; }Returns true if this shape is a WordArt object.
LastChild { get; }Gets the last child of the node.
Left { get; set; }Gets or sets the position of the left edge of the containing block of the shape.
LeftRelative { get; set; }Gets or sets the value that represents shape’s relative left position in percent.
MarkupLanguage { get; }Gets MarkupLanguage used for this graphic object.
Name { get; set; }Gets or sets the optional shape name.
NextSibling { get; }Gets the node immediately following this node.
override NodeType { get; }Returns GroupShape.
ParentNode { get; }Gets the immediate parent of this node.
ParentParagraph { get; }Returns the immediate parent paragraph.
PreviousSibling { get; }Gets the node immediately preceding this node.
Range { get; }Returns a Range object that represents the portion of a document that is contained in this node.
Reflection { get; }Gets reflection formatting for the shape.
RelativeHorizontalPosition { get; set; }Specifies relative to what the shape is positioned horizontally.
RelativeHorizontalSize { get; set; }Gets or sets the value of shape’s relative size in horizontal direction.
RelativeVerticalPosition { get; set; }Specifies relative to what the shape is positioned vertically.
RelativeVerticalSize { get; set; }Gets or sets the value of shape’s relative size in vertical direction.
Right { get; }Gets the position of the right edge of the containing block of the shape.
Rotation { get; set; }Defines the angle (in degrees) that a shape is rotated. Positive value corresponds to clockwise rotation angle.
ScreenTip { get; set; }Defines the text displayed when the mouse pointer moves over the shape.
ShadowFormat { get; }Gets shadow formatting for the shape.
ShapeType { get; }Gets the shape type.
SizeInPoints { get; }Gets the size of the shape in points.
SoftEdge { get; }Gets soft edge formatting for the shape.
Target { get; set; }Gets or sets the target frame for the shape hyperlink.
Title { get; set; }Gets or sets the title (caption) of the current shape object.
Top { get; set; }Gets or sets the position of the top edge of the containing block of the shape.
TopRelative { get; set; }Gets or sets the value that represents shape’s relative top position in percent.
VerticalAlignment { get; set; }Specifies how the shape is positioned vertically.
Width { get; set; }Gets or sets the width of the containing block of the shape.
WidthRelative { get; set; }Gets or sets the value that represents the percentage of shape’s relative width.
WrapSide { get; set; }Specifies how the text is wrapped around the shape.
WrapType { get; set; }Defines whether the shape is inline or floating. For floating shapes defines the wrapping mode for text around the shape.
ZOrder { get; set; }Determines the display order of overlapping shapes.

Methods

NameDescription
override Accept(DocumentVisitor)Accepts a visitor.
override AcceptEnd(DocumentVisitor)Accepts a visitor for visiting the end of the GroupShape.
override AcceptStart(DocumentVisitor)Accepts a visitor for visiting the start of the GroupShape.
AdjustWithEffects(RectangleF)Adds to the source rectangle values of the effect extent and returns the final rectangle.
AppendChild<T>(T)Adds the specified node to the end of the list of child nodes for this node.
Clone(bool)Creates a duplicate of the node.
CreateNavigator()Creates navigator which can be used to traverse and read nodes.
GetAncestor(NodeType)Gets the first ancestor of the specified NodeType.
GetAncestor(Type)Gets the first ancestor of the specified object type.
GetChild(NodeType, int, bool)Returns an Nth child node that matches the specified type.
GetChildNodes(NodeType, bool)Returns a live collection of child nodes that match the specified type.
GetEnumerator()Provides support for the for each style iteration over the child nodes of this node.
GetShapeRenderer()Creates and returns an object that can be used to render this shape into an image.
override GetText()Gets the text of this node and of all its children.
IndexOf(Node)Returns the index of the specified child node in the child node array.
InsertAfter<T>(T, Node)Inserts the specified node immediately after the specified reference node.
InsertBefore<T>(T, Node)Inserts the specified node immediately before the specified reference node.
LocalToParent(PointF)Converts a value from the local coordinate space into the coordinate space of the parent shape.
NextPreOrder(Node)Gets next node according to the pre-order tree traversal algorithm.
PrependChild<T>(T)Adds the specified node to the beginning of the list of child nodes for this node.
PreviousPreOrder(Node)Gets the previous node according to the pre-order tree traversal algorithm.
Remove()Removes itself from the parent.
RemoveAllChildren()Removes all the child nodes of the current node.
RemoveChild<T>(T)Removes the specified child node.
RemoveSmartTags()Removes all SmartTag descendant nodes of the current node.
SelectNodes(string)Selects a list of nodes matching the XPath expression.
SelectSingleNode(string)Selects the first Node that matches the XPath expression.
ToString(SaveFormat)Exports the content of the node into a string in the specified format.
ToString(SaveOptions)Exports the content of the node into a string using the specified save options.

Remarks

A GroupShape is a composite node and can have Shape and GroupShape nodes as children.

Each GroupShape defines a new coordinate system for its child shapes. The coordinate system is defined using the CoordSize and CoordOrigin properties.

Examples

Shows how to create a group of shapes, and print its contents using a document visitor.

public void GroupOfShapes()
{
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // If you need to create "NonPrimitive" shapes, such as SingleCornerSnipped, TopCornersSnipped, DiagonalCornersSnipped,
    // TopCornersOneRoundedOneSnipped, SingleCornerRounded, TopCornersRounded, DiagonalCornersRounded
    // please use DocumentBuilder.InsertShape methods.
    Shape balloon = new Shape(doc, ShapeType.Balloon)
    {
        Width = 200,
        Height = 200,
        Stroke = { Color = Color.Red }
    };

    Shape cube = new Shape(doc, ShapeType.Cube)
    {
        Width = 100,
        Height = 100,
        Stroke = { Color = Color.Blue }
    };

    GroupShape group = new GroupShape(doc);
    group.AppendChild(balloon);
    group.AppendChild(cube);

    Assert.True(group.IsGroup);

    builder.InsertNode(group);

    ShapeGroupPrinter printer = new ShapeGroupPrinter();
    group.Accept(printer);

    Console.WriteLine(printer.GetText());
}

/// <summary>
/// Prints the contents of a visited shape group to the console.
/// </summary>
public class ShapeGroupPrinter : DocumentVisitor
{
    public ShapeGroupPrinter()
    {
        mBuilder = new StringBuilder();
    }

    public string GetText()
    {
        return mBuilder.ToString();
    }

    public override VisitorAction VisitGroupShapeStart(GroupShape groupShape)
    {
        mBuilder.AppendLine("Shape group started:");
        return VisitorAction.Continue;
    }

    public override VisitorAction VisitGroupShapeEnd(GroupShape groupShape)
    {
        mBuilder.AppendLine("End of shape group");
        return VisitorAction.Continue;
    }

    public override VisitorAction VisitShapeStart(Shape shape)
    {
        mBuilder.AppendLine("\tShape - " + shape.ShapeType + ":");
        mBuilder.AppendLine("\t\tWidth: " + shape.Width);
        mBuilder.AppendLine("\t\tHeight: " + shape.Height);
        mBuilder.AppendLine("\t\tStroke color: " + shape.Stroke.Color);
        mBuilder.AppendLine("\t\tFill color: " + shape.Fill.ForeColor);
        return VisitorAction.Continue;
    }

    public override VisitorAction VisitShapeEnd(Shape shape)
    {
        mBuilder.AppendLine("\tEnd of shape");
        return VisitorAction.Continue;
    }

    private readonly StringBuilder mBuilder;
}

See Also