Click or drag to resize

Shape Class

Represents a shape.
Inheritance Hierarchy

Namespace:  SautinSoft.Document.Drawing
Assembly:  SautinSoft.Document (in SautinSoft.Document.dll) Version: 3.8.6.14 (3.8.6.14)
Syntax
public class Shape : ShapeBase, IContentElement

The Shape type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleShape
Initializes a new instance of the Shape class.
Top
Properties
  NameDescription
Public propertyCharacterFormat
Gets or sets the character format.
(Inherited from ShapeBase.)
Public propertyContent
Gets the ContentRange of the current element.
(Inherited from Element.)
Public propertyDocument
Gets the owner document.
(Inherited from Element.)
Public propertyElementType
Gets the ElementType of this element instance.
(Overrides ElementElementType.)
Public propertyFill
Gets the Brush that specifies how the shape's interior is filled.
(Inherited from ShapeBase.)
Public propertyFlipOrientation
Gets or sets the orientation of a shape.
(Inherited from ShapeBase.)
Public propertyCode exampleGeometry
Gets a shape's geometry.
Public propertyIsTopLevel
Returns true if this shape is not a child of a group shape.
(Inherited from ShapeBase.)
Public propertyLayout
Gets or sets the ShapeBase layout (position and size).
(Inherited from ShapeBase.)
Public propertyNextSibling
Gets the next Element sibling.
(Inherited from Element.)
Public propertyOutline
Gets the Pen that specifies the shape's outline.
Public propertyParent
Gets the parent of this element instance.
(Inherited from Element.)
Public propertyParentCollection
Gets the InlineCollection that contains this Inline instance.
(Inherited from Inline.)
Public propertyParentGroup
Gets the parent group shape.
(Inherited from ShapeBase.)
Public propertyPreviuosSibling
Gets the previous Element sibling.
(Inherited from Element.)
Public propertyRotation
Gets or sets the angle (in degrees) that a shape is rotated. Positive value corresponds to clockwise rotation angle.
(Inherited from ShapeBase.)
Public propertyCode exampleText
Gets a shape's text.
Top
Methods
  NameDescription
Public methodClone
Clones this element instance.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodCode exampleGetChildElements(Boolean)
Gets the child elements.
(Inherited from Element.)
Public methodCode exampleGetChildElements(Boolean, ElementType)
Gets the child elements filtered by ElementType.
(Inherited from Element.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Explicit Interface Implementations
Examples
How to work with Shapes in C#
using SautinSoft.Document;
using SautinSoft.Document.Drawing;

namespace Sample
{
    class Sample
    {

        static void Main(string[] args)
        {
            Shapes();
        }

        /// <summary>
        /// This sample shows how to work with shapes. 
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/examples/shapes.php
        /// </remarks>
        public static void Shapes()
        {
            string documentPath = @"Shapes.docx";

            // Let's create a new document.
            DocumentCore dc = new DocumentCore();

            // Create shape 1 with fill and outline.
            Shape shp1 = new Shape(dc, Layout.Floating(
                new HorizontalPosition(25f, LengthUnit.Millimeter, HorizontalPositionAnchor.LeftMargin),
                new VerticalPosition(20f, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin),
                new Size(200, 100)
                ));

            // Specify outline and fill using a picture.
            shp1.Outline.Fill.SetSolid(Color.DarkGreen);
            shp1.Outline.Width = 2;

            // Set fill for this shape.
            shp1.Fill.SetSolid(Color.Orange);

            // Create shape 2 with some text inside, 100mm*20mm.
            Shape shp2 = new Shape(dc, Layout.Floating(
                new HorizontalPosition(100f, LengthUnit.Millimeter, HorizontalPositionAnchor.LeftMargin),
                new VerticalPosition(20f, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin),
                new Size(LengthUnitConverter.Convert(100f, LengthUnit.Millimeter, LengthUnit.Point),
                        LengthUnitConverter.Convert(20f, LengthUnit.Millimeter, LengthUnit.Point))
                ));

            // Specify outline and fill using a picture.
            shp2.Outline.Fill.SetSolid(Color.LightGray);
            shp2.Outline.Width = 0.5;

            // Create a new paragraph with a formatted text.
            Paragraph p = new Paragraph(dc);
            Run run1 = new Run(dc, "Welcome to International Software Developer conference!");
            run1.CharacterFormat.FontName = "Helvetica";
            run1.CharacterFormat.Size = 14f;
            run1.CharacterFormat.Italic = true;
            p.Inlines.Add(run1);

            // Add the paragraph into the shp2.Text property.
            shp2.Text.Blocks.Add(p);

            // Add our shapes into the document.
            dc.Content.End.Insert(shp1.Content);
            dc.Content.End.Insert(shp2.Content);

            // Save the document to DOCX format.
            dc.Save(documentPath);

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(documentPath) { UseShellExecute = true });
        }
    }
}
How to work with Shapes in VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document
Imports SautinSoft.Document.Drawing

Module Sample
    Sub Main()
        Shapes()
    End Sub

    ''' <summary>
    ''' This sample shows how to work with shapes. 
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/examples/shapes.php
    ''' </remarks>
    Sub Shapes()
        Dim documentPath As String = "Shapes.docx"

        ' Let's create a new document.
        Dim dc As New DocumentCore()

        ' Create shape 1 with fill and outline.
        Dim shp1 As New Shape(dc, Layout.Floating(New HorizontalPosition(25.0F, LengthUnit.Millimeter, HorizontalPositionAnchor.LeftMargin), New VerticalPosition(20.0F, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin), New Size(200, 100)))

        ' Specify outline and fill using a picture.
        shp1.Outline.Fill.SetSolid(Color.DarkGreen)
        shp1.Outline.Width = 2

        ' Set fill for this shape.
        shp1.Fill.SetSolid(Color.Orange)

        ' Create shape 2 with some text inside, 100mm*20mm.
        Dim shp2 As New Shape(dc, Layout.Floating(New HorizontalPosition(100.0F, LengthUnit.Millimeter, HorizontalPositionAnchor.LeftMargin), New VerticalPosition(20.0F, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin), New Size(LengthUnitConverter.Convert(100.0F, LengthUnit.Millimeter, LengthUnit.Point), LengthUnitConverter.Convert(20.0F, LengthUnit.Millimeter, LengthUnit.Point))))

        ' Specify outline and fill using a picture.
        shp2.Outline.Fill.SetSolid(Color.LightGray)
        shp2.Outline.Width = 0.5

        ' Create a new paragraph with a formatted text.
        Dim p As New Paragraph(dc)
        Dim run1 As New Run(dc, "Welcome to International Software Developer conference!")
        run1.CharacterFormat.FontName = "Helvetica"
        run1.CharacterFormat.Size = 14.0F
        run1.CharacterFormat.Italic = True
        p.Inlines.Add(run1)

        ' Add the paragraph into the shp2.Text property.
        shp2.Text.Blocks.Add(p)

        ' Add our shapes into the document.
        dc.Content.End.Insert(shp1.Content)
        dc.Content.End.Insert(shp2.Content)

        ' Save the document to DOCX format.
        dc.Save(documentPath)

        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(documentPath) With {.UseShellExecute = True})
    End Sub
End Module
See Also