Shape Constructor
Creates a new shape object.

Namespace: Aspose.Words.Drawing
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.12
Syntax
public Shape(
	DocumentBase doc,
	ShapeType shapeType
)

Parameters

doc
Type: Aspose.WordsDocumentBase
The owner document.
shapeType
Type: Aspose.Words.DrawingShapeType
The type of the shape to create.
Remarks

You should specify desired shape properties after you created a shape.

Examples
Shows how to create shape and add an image to a document without using a document builder.
Document doc = new Document();

// Public constructor of "Shape" class creates shape with "ShapeMarkupLanguage.Vml" markup type
// If you need to create "NonPrimitive" shapes, like SingleCornerSnipped, TopCornersSnipped, DiagonalCornersSnipped,
// TopCornersOneRoundedOneSnipped, SingleCornerRounded, TopCornersRounded, DiagonalCornersRounded
// please use DocumentBuilder.InsertShape methods
Shape shape = new Shape(doc, ShapeType.Image);
shape.ImageData.SetImage(MyDir + "Images/Hammer.wmf");
shape.Width = 100;
shape.Height = 100;

doc.FirstSection.Body.FirstParagraph.AppendChild(shape);

doc.Save(ArtifactsDir + "Image.CreateImageDirectly.doc");
Examples
Creates a textbox with some text and different formatting options in a new document.
// Create a blank document.
Document doc = new Document();

// Create a new shape of type TextBox
Shape textBox = new Shape(doc, ShapeType.TextBox);

// Set some settings of the textbox itself.
// Set the wrap of the textbox to inline
textBox.WrapType = WrapType.None;
// Set the horizontal and vertical alignment of the text inside the shape.
textBox.HorizontalAlignment = HorizontalAlignment.Center;
textBox.VerticalAlignment = VerticalAlignment.Top;

// Set the textbox height and width.
textBox.Height = 50;
textBox.Width = 200;

// Set the textbox in front of other shapes with a lower ZOrder
textBox.ZOrder = 2;

// Let's create a new paragraph for the textbox manually and align it in the center. Make sure we add the new nodes to the textbox as well.
textBox.AppendChild(new Paragraph(doc));
Paragraph para = textBox.FirstParagraph;
para.ParagraphFormat.Alignment = ParagraphAlignment.Center;

// Add some text to the paragraph.
Run run = new Run(doc);
run.Text = "Content in textbox";
para.AppendChild(run);

// Append the textbox to the first paragraph in the body.
doc.FirstSection.Body.FirstParagraph.AppendChild(textBox);

// Save the output
doc.Save(ArtifactsDir + "Shape.CreateTextBox.doc");
See Also