Class Shape
Represents the shapes and it manipulations in the Word document.
Inheritance
Inherited Members
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.UWP.dll
Syntax
public class Shape : ShapeBase, IXDLSSerializable, IWidget, IParagraphItem, IOfficeRun, IEntity
Examples
The following code example demonstrates how to add new shape to document.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument("Template.docx");
//Add the section into Word document
WSection section = document.AddSection() as WSection;
//Add a paragraph to created section
WParagraph paragraph = document.Sections[0].Paragraphs[0];
//Create a new shape
Syncfusion.DocIO.DLS.Shape shape = new Syncfusion.DocIO.DLS.Shape(document, AutoShapeType.Rectangle);
//Specify the shape formatting options
shape.AlternativeText = "demo shape";
shape.FillFormat.Color = Color.LightBlue;
shape.Height = 75;
shape.Width = 100;
shape.HorizontalAlignment = ShapeHorizontalAlignment.Left;
shape.HorizontalOrigin = HorizontalOrigin.Margin;
shape.LineFormat.Line = true;
shape.LineFormat.Style = Syncfusion.DocIO.DLS.LineStyle.Single;
shape.Name = "Rectangle";
shape.Title = "Rectangle shape demo";
shape.VerticalAlignment = ShapeVerticalAlignment.Center;
shape.VerticalOrigin = VerticalOrigin.Page;
shape.WrapFormat.TextWrappingStyle = TextWrappingStyle.Square;
string paraText = "Lorem ipsum dolor sit amet, lacus amet amet ultricies. Quisque mi venenatis morbi libero, orci dis, mi ut et class porta, massa ligula magna enim, aliquam orci vestibulum Turpis facilisis vitae consequat, cum a a,turpis dui consequat massa in dolor per, felis non amet.Auctor eleifend in omnis elit vestibulum, donec non elementum tellus est mauris, id aliquam, at lacus, arcu pretium proin lacus dolor et. Eu tortor, vel ultrices amet dignissim mauris vehicula";
//Add the new paragraph to shape with some text
shape.TextBody.AddParagraph().AppendText(paraText);
//Add the shape to paragraph
paragraph.ChildEntities.Add(shape);
//Save and close the Word document instance
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument("Template.docx")
'Add the section into Word document
Dim section As WSection = TryCast(document.AddSection(), WSection)
'Add a paragraph to created section
Dim paragraph As WParagraph = document.Sections(0).Paragraphs(0)
'Create a new shape
Dim shape As New Syncfusion.DocIO.DLS.Shape(document, AutoShapeType.Rectangle)
'Specify the shape formatting options
shape.AlternativeText = "demo shape"
shape.FillFormat.Color = Color.LightBlue
shape.Height = 75
shape.Width = 100
shape.HorizontalAlignment = ShapeHorizontalAlignment.Left
shape.HorizontalOrigin = HorizontalOrigin.Margin
shape.LineFormat.Line = True
shape.LineFormat.Style = Syncfusion.DocIO.DLS.LineStyle.[Single]
shape.Name = "Rectangle"
shape.Title = "Rectangle shape demo"
shape.VerticalAlignment = ShapeVerticalAlignment.Center
shape.VerticalOrigin = VerticalOrigin.Page
shape.WrapFormat.TextWrappingStyle = TextWrappingStyle.Square
Dim paraText As String = "Lorem ipsum dolor sit amet, lacus amet amet ultricies. Quisque mi venenatis morbi libero, orci dis, mi ut et class porta, massa ligula magna enim, aliquam orci vestibulum Turpis facilisis vitae consequat, cum a a,turpis dui consequat massa in dolor per, felis non amet.Auctor eleifend in omnis elit vestibulum, donec non elementum tellus est mauris, id aliquam, at lacus, arcu pretium proin lacus dolor et. Eu tortor, vel ultrices amet dignissim mauris vehicula"
'Add the new paragraph to shape with some text
shape.TextBody.AddParagraph().AppendText(paraText)
'Add the shape to paragraph
paragraph.ChildEntities.Add(shape)
'Save and close the Word document instance
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
Constructors
Shape(IWordDocument, AutoShapeType)
Initializes a new instance of Shape class with the specified IWordDocument instance and the shape type.
Declaration
public Shape(IWordDocument doc, AutoShapeType autoShapeType)
Parameters
Type | Name | Description |
---|---|---|
IWordDocument | doc | The IWordDocument instance. |
AutoShapeType | autoShapeType | The type of the shape. |
Fields
ShapeTypeID
Variable that specifies the shape type ID.
Declaration
public string ShapeTypeID
Field Value
Type |
---|
System.String |
Properties
AutoShapeType
Gets the shape type of the current shape object. Read-only.
Declaration
public AutoShapeType AutoShapeType { get; }
Property Value
Type | Description |
---|---|
AutoShapeType | The AutoShapeType member that specifies the type of the shape. |
Remarks
The shape type must represent an AutoShape other than a line or free form drawing.
EntityType
Gets the type of the entity.
Declaration
public override EntityType EntityType { get; }
Property Value
Type | Description |
---|---|
EntityType | The EntityType of the current item. |
Overrides
FillFormat
Gets or sets the fill effects for the shape.
Declaration
public FillFormat FillFormat { get; set; }
Property Value
Type | Description |
---|---|
FillFormat | The FillFormat instance. |
FlipHorizontal
Gets or sets a Horizontal flipping of Shape.
Declaration
public bool FlipHorizontal { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Remarks
This property returns True if the specified shape is flipped around the horizontal axis, and False if not.
Examples
The following code example demonstrates how to gets or sets the horizontal flip to rectangle shape.
//Creates a new Word document
WordDocument document = new WordDocument();
//Adds new section to the document
IWSection section = document.AddSection();
//Adds new paragraph to the section
WParagraph paragraph = section.AddParagraph() as WParagraph;
//Adds new shape to the document
Shape rectangle = paragraph.AppendShape(AutoShapeType.RoundedRectangle, 150, 100);
//Adds textbody contents to the shape
paragraph = rectangle.TextBody.AddParagraph() as WParagraph;
IWTextRange text = paragraph.AppendText("This text is in rounded rectangle shape");
//Sets horizontal flip to the rectangle shape
rectangle.FlipHorizontal = true;
//Saves the Word document
document.Save("Sample.docx", FormatType.Docx);
//Closes the document
document.Close();
'Creates a new Word document
Dim document As WordDocument = New WordDocument
'Adds new section to the document
Dim section As IWSection = document.AddSection
'Adds new paragraph to the section
Dim paragraph As WParagraph = CType(section.AddParagraph, WParagraph)
'Adds new shape to the document
Dim rectangle As Shape = paragraph.AppendShape(AutoShapeType.RoundedRectangle, 150, 100)
'Adds textbody contents to the shape
paragraph = CType(rectangle.TextBody.AddParagraph, WParagraph)
Dim text As IWTextRange = paragraph.AppendText("This text is in rounded rectangle shape")
'Sets horizontal flip to the rectangle shape
rectangle.FlipHorizontal = True
'Saves the Word document
document.Save("Sample.docx", FormatType.Docx)
'Closes the document
document.Close()
FlipVertical
Gets or sets a Vertical flipping of Shape.
Declaration
public bool FlipVertical { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Remarks
This property returns True if the specified shape is flipped around the vertical axis, and False if not.
Examples
The following code example demonstrates how to gets or sets the vertical flip to rectangle shape.
//Creates a new Word document
WordDocument document = new WordDocument();
//Adds new section to the document
IWSection section = document.AddSection();
//Adds new paragraph to the section
WParagraph paragraph = section.AddParagraph() as WParagraph;
//Adds new shape to the document
Shape rectangle = paragraph.AppendShape(AutoShapeType.RoundedRectangle, 150, 100);
//Adds textbody contents to the shape
paragraph = rectangle.TextBody.AddParagraph() as WParagraph;
IWTextRange text = paragraph.AppendText("This text is in rounded rectangle shape");
//Sets vertical flip to the rectangle shape
rectangle.FlipVertical = true;
//Saves the Word document
document.Save("Sample.docx", FormatType.Docx);
//Closes the document
document.Close();
'Creates a new Word document
Dim document As WordDocument = New WordDocument
'Adds new section to the document
Dim section As IWSection = document.AddSection
'Adds new paragraph to the section
Dim paragraph As WParagraph = CType(section.AddParagraph, WParagraph)
'Adds new shape to the document
Dim rectangle As Shape = paragraph.AppendShape(AutoShapeType.RoundedRectangle, 150, 100)
'Adds textbody contents to the shape
paragraph = CType(rectangle.TextBody.AddParagraph, WParagraph)
Dim text As IWTextRange = paragraph.AppendText("This text is in rounded rectangle shape")
'Sets vertical flip to the rectangle shape
rectangle.FlipVertical = True
'Saves the Word document
document.Save("Sample.docx", FormatType.Docx)
'Closes the document
document.Close()
LineFormat
Gets or sets the line formatting options for outline of the shape.
Declaration
public LineFormat LineFormat { get; set; }
Property Value
Type | Description |
---|---|
LineFormat | The LineFormat instance. |
Rotation
Gets or sets the shape rotation in degree.
Declaration
public float Rotation { get; set; }
Property Value
Type | Description |
---|---|
System.Single | The float that specifies the rotation value of the shape. |
Remarks
A positive value indicates clockwise rotation; a negative value indicates counterclockwise rotation.
Examples
The following code example demonstrates how to gets or sets the rotation value of rectangle shape in degree.
//Creates a new Word document
WordDocument document = new WordDocument();
//Adds new section to the document
IWSection section = document.AddSection();
//Adds new paragraph to the section
WParagraph paragraph = section.AddParagraph() as WParagraph;
//Adds new shape to the document
Shape rectangle = paragraph.AppendShape(AutoShapeType.RoundedRectangle, 150, 100);
//Adds textbody contents to the shape
paragraph = rectangle.TextBody.AddParagraph() as WParagraph;
IWTextRange text = paragraph.AppendText("This text is in rounded rectangle shape");
//Sets rectangle shape rotation in degree
rectangle.Rotation = 90;
//Saves the Word document
document.Save("Sample.docx", FormatType.Docx);
//Closes the document
document.Close();
'Creates a new Word document
Dim document As WordDocument = New WordDocument
'Adds new section to the document
Dim section As IWSection = document.AddSection
'Adds new paragraph to the section
Dim paragraph As WParagraph = CType(section.AddParagraph, WParagraph)
'Adds new shape to the document
Dim rectangle As Shape = paragraph.AppendShape(AutoShapeType.RoundedRectangle, 150, 100)
'Adds textbody contents to the shape
paragraph = CType(rectangle.TextBody.AddParagraph, WParagraph)
Dim text As IWTextRange = paragraph.AppendText("This text is in rounded rectangle shape")
'Sets rectangle shape rotation in degree
rectangle.Rotation = 90
'Saves the Word document
document.Save("Sample.docx", FormatType.Docx)
'Closes the document
document.Close()
TextBody
Gets or sets the text body for the shape.
Declaration
public WTextBody TextBody { get; set; }
Property Value
Type | Description |
---|---|
WTextBody | The WTextBody that specifies the shape body contents. |
TextFrame
Gets or sets the TextFrame for the shape.
Declaration
public TextFrame TextFrame { get; set; }
Property Value
Type | Description |
---|---|
TextFrame | The TextFrame instance that specifies the formatting options for text. |
Methods
ApplyCharacterFormat(WCharacterFormat)
Applies the specified character format to the shape.
Declaration
public void ApplyCharacterFormat(WCharacterFormat charFormat)
Parameters
Type | Name | Description |
---|---|---|
WCharacterFormat | charFormat | The character format to be applied. |
CloneImpl()
Creates a duplicate copy of this Shape object.
Declaration
protected override object CloneImpl()
Returns
Type | Description |
---|---|
System.Object | The reference of the newly created Shape. |