TextBox Class
Defines attributes that specify how a text is displayed inside a shape.
Inheritance Hierarchy

Namespace: Aspose.Words.Drawing
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.8
public class TextBox

The TextBox type exposes the following members.

Public propertyCode exampleFitShapeToText
Determines whether Microsoft Word will grow the shape to fit text.
Public propertyCode exampleInternalMarginBottom
Specifies the inner bottom margin in points for a shape.
Public propertyCode exampleInternalMarginLeft
Specifies the inner left margin in points for a shape.
Public propertyCode exampleInternalMarginRight
Specifies the inner right margin in points for a shape.
Public propertyCode exampleInternalMarginTop
Specifies the inner top margin in points for a shape.
Public propertyCode exampleLayoutFlow
Determines the flow of the text layout in a shape.
Public propertyNext
Returns or sets a TextBox that represents the next TextBox in a sequence of shapes.
Public propertyParent
Gets a parent shape for the TextBox.
Public propertyPrevious
Returns a TextBox that represents the previous TextBox in a sequence of shapes.
Public propertyCode exampleTextBoxWrapMode
Determines how text wraps inside a shape.
Public propertyCode exampleVerticalAnchor
Specifies the vertical alignment of the text within a shape.
Public methodBreakForwardLink
Breaks the link to the next TextBox.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the type of the current instance.
(Inherited from Object.)
Public methodIsValidLinkTarget
Determines whether this TextBox can be linked to the target Textbox.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)

Use the TextBox property to access text properties of a shape. You do not create instances of the TextBox class directly.

Shows how to insert text boxes and arrange their text.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a shape that contains a TextBox
Shape textBoxShape = builder.InsertShape(ShapeType.TextBox, 150, 100);
TextBox textBox = textBoxShape.TextBox;

// Move the document builder to inside the TextBox and write text
builder.Write("Vertical text");

// Text is displayed vertically, written top to bottom
textBox.LayoutFlow = LayoutFlow.TopToBottomIdeographic;

// Move the builder out of the shape and back into the main document body

// Insert another TextBox
textBoxShape = builder.InsertShape(ShapeType.TextBox, 150, 100);
textBox = textBoxShape.TextBox;

// Apply these values to both these members to get the parent shape to defy the dimensions we set to fit tightly around the TextBox's text
textBox.FitShapeToText = true;
textBox.TextBoxWrapMode = TextBoxWrapMode.None;

builder.Write("Text fit tightly inside textbox");


textBoxShape = builder.InsertShape(ShapeType.TextBox, 100, 100);
textBox = textBoxShape.TextBox;

// Set margins for the textbox
textBox.InternalMarginTop = 15;
textBox.InternalMarginBottom = 15;
textBox.InternalMarginLeft = 15;
textBox.InternalMarginRight = 15;

builder.Write("Text placed according to textbox margins");

doc.Save(ArtifactsDir + "Drawing.TextBox.docx");
See Also