Click or drag to resize

ShapeBase Class

Base class for all drawing objects, such as a Shape, ShapeGroup or Picture.
Inheritance Hierarchy
SystemObject
  SautinSoft.DocumentElement
    SautinSoft.DocumentInline
      SautinSoft.Document.DrawingShapeBase
        SautinSoft.Document.DrawingShape
        SautinSoft.Document.DrawingShapeGroup

Namespace: SautinSoft.Document.Drawing
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.7.18
Syntax
public abstract class ShapeBase : Inline

The ShapeBase type exposes the following members.

Properties
 NameDescription
Public propertyCharacterFormat Gets or sets the character format.
Public propertyDescription Specifies alternative text for the current DrawingML object, for use by assistive technologies or applications which do not display the current object. If this element is omitted, then no alternative text is present for the parent object.
Public propertyFill Gets the Brush that specifies how the shape's interior is filled.
Public propertyFlipOrientation Gets or sets the orientation of a shape.
Public propertyIsTopLevel Returns true if this shape is not a child of a group shape.
Public propertyLayout Gets or sets the ShapeBase layout (position and size).
Public propertyParentGroup Gets the parent group shape.
Public propertyRotation Gets or sets the angle (in degrees) that a shape is rotated. Positive value corresponds to clockwise rotation angle.
Top
Methods
 NameDescription
Public methodClone Clones this element instance.
Top
Example

See Developer Guide: Insert an image and shape inline or in the specified position

Insert an image and shape inline or in the specified position using C#
using System;
using SautinSoft.Document;
using System.Text;
using SautinSoft.Document.Drawing;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            // Get your free 100-day key here:   
            // https://sautinsoft.com/start-for-free/
            InsertingImage();
        }
        /// <summary>
        /// Insert an image and shape inline or in the specified position using DocumentBuilder.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/documentbuilder-inserting-image.php
        /// </remarks>

        static void InsertingImage()
        {
            DocumentCore dc = new DocumentCore();
            DocumentBuilder db = new DocumentBuilder(dc);

            string resultPath = @"Result.docx";
            string pictPath = @"..\..\..\logo.png";

            // Insert the formatted text into the document using DocumentBuilder.
            db.CharacterFormat.FontName = "Courier";
            db.CharacterFormat.Size = 17f;
            db.CharacterFormat.Italic = true;
            db.CharacterFormat.FontColor = Color.Orange;
            db.Writeln("Insert an Image and Shape using DocumentBuilder.");

            // Images:
            // 1st way: Insert an Inline image into the document.
            // Specify the image size and rotation (if required).
            Picture pict1 = db.InsertImage(pictPath, new Size(100, 30, LengthUnit.Millimeter));
            pict1.Rotation = -3;

            // 2nd way: Insert a Floating image from a file at the specified position.
            Picture pict2 = db.InsertImage(pictPath, new HorizontalPosition(1, LengthUnit.Centimeter, HorizontalPositionAnchor.LeftMargin),
                 new VerticalPosition(8, LengthUnit.Centimeter, VerticalPositionAnchor.TopMargin), WrappingStyle.InFrontOfText);

            // Shapes:
            // 1st way: Insert an Inline shape.
            Shape shp1 = db.InsertShape(Figure.SmileyFace, new Size(3, 3, LengthUnit.Centimeter));

            // 2nd way: Insert a Floating shape with specified position, size and text wrap style.
            Size size1 = new Size(7, 6, LengthUnit.Centimeter);
            Shape shp2 = db.InsertShape(Figure.RoundRectangle, new HorizontalPosition(8, LengthUnit.Centimeter,HorizontalPositionAnchor.LeftMargin), 
                new VerticalPosition(10, LengthUnit.Centimeter, VerticalPositionAnchor.TopMargin), WrappingStyle.InFrontOfText, new Size(7, 6, LengthUnit.Centimeter));

            shp2.Fill.SetSolid(Color.White);

            // Move the "cursor" position inside the shape content.
            db.MoveTo(shp2.Text.Blocks.Content.Start);
            db.CharacterFormat.FontColor = Color.Green;
            db.CharacterFormat.Size = 26f;
            db.Writeln("Text inside Shape.");

            // Move the "cursor" back to the paragraph with "shp1".
            db.MoveTo(shp1.Content.End);            

            // Save our document into DOCX format.
            dc.Save(resultPath, new DocxSaveOptions());

            // Important for Linux: Install MS Fonts
            // sudo apt install ttf-mscorefonts-installer -y

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(resultPath) { UseShellExecute = true });
        }
    }
}
Insert an image and shape inline or in the specified position using VB.Net
Imports System
Imports SautinSoft.Document
Imports System.Text
Imports SautinSoft.Document.Drawing

Namespace Example
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            InsertingImage()
        End Sub
                ''' Get your free 100-day key here:   
                ''' https://sautinsoft.com/start-for-free/
        ''' <summary>
        ''' Insert an image and shape inline or in the specified position using DocumentBuilder.
        ''' </summary>
        ''' <remarks>
        ''' Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/documentbuilder-inserting-image.php
        ''' </remarks>

        Private Shared Sub InsertingImage()
            Dim dc As New DocumentCore()
            Dim db As New DocumentBuilder(dc)

            Dim resultPath As String = "result.docx"
            Dim pictPath As String = "..\..\..\logo.png"

            ' Insert the formatted text into the document using DocumentBuilder.
            db.CharacterFormat.FontName = "Courier"
            db.CharacterFormat.Size = 17.0F
            db.CharacterFormat.Italic = True
            db.CharacterFormat.FontColor = Color.Orange
            db.Writeln("Insert an Image and Shape using DocumentBuilder.")

            ' Images:
            ' 1st way: Insert an Inline image into the document.
            ' Specify the image size and rotation (if required).
            Dim pict1 As Picture = db.InsertImage(pictPath, New Size(100, 30, LengthUnit.Millimeter))
            pict1.Rotation = -3

            ' 2nd way: Insert a Floating image from a file at the specified position.
            Dim pict2 As Picture = db.InsertImage(pictPath, New HorizontalPosition(1, LengthUnit.Centimeter, HorizontalPositionAnchor.LeftMargin), New VerticalPosition(8, LengthUnit.Centimeter, VerticalPositionAnchor.TopMargin), WrappingStyle.InFrontOfText)

            ' Shapes:
            ' 1st way: Insert an Inline shape.
            Dim shp1 As Shape = db.InsertShape(Figure.SmileyFace, New Size(3, 3, LengthUnit.Centimeter))

            ' 2nd way: Insert a Floating shape with specified position, size and text wrap style.
            Dim size1 As New Size(7, 6, LengthUnit.Centimeter)
            Dim shp2 As Shape = db.InsertShape(Figure.RoundRectangle, New HorizontalPosition(8, LengthUnit.Centimeter, HorizontalPositionAnchor.LeftMargin), New VerticalPosition(10, LengthUnit.Centimeter, VerticalPositionAnchor.TopMargin), WrappingStyle.InFrontOfText, New Size(7, 6, LengthUnit.Centimeter))

            shp2.Fill.SetSolid(Color.White)

            ' Move the "cursor" position inside the shape content.
            db.MoveTo(shp2.Text.Blocks.Content.Start)
            db.CharacterFormat.FontColor = Color.Green
            db.CharacterFormat.Size = 26.0F
            db.Writeln("Text inside Shape.")

            ' Move the "cursor" back to the paragraph with "shp1".
            db.MoveTo(shp1.Content.End)

            ' Save our document into DOCX format.
            dc.Save(resultPath, New DocxSaveOptions())

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