Working with Linked TextBoxes

In Aspose.Words, the TextBox class is used to specify how text is displayed inside a shape. It exposes a public property named Parent to get the parent shape for the text box so that the customer can find the linked Shape from the associated TextBox.

The TextBox class provides isValidLinkTarget() method in order to check whether the TextBox can be linked to the target Textbox.

The following code example shows how to check if the TextBox can be linked to the target Textbox:

Check TextBox Sequence

There are several ways to display text in a shape. The getTextBox() can be the Head, Middle, or Tail of a sequence.

The following code example shows how to check if TextBox is a Head, Tail, or Middle of the sequence:

Using the breakForwardLink() method you can break the link to the next TextBox.

The following code example shows how to break a link for a TextBox:

FAQ

  1. Q: How can I check if a TextBox can be linked to another TextBox?
    A: Call textBox.isValidLinkTarget(targetTextBox). The method returns true when the two text boxes belong to the same document and satisfy the linking rules; otherwise it returns false.

  2. Q: How do I obtain the shape that contains a linked TextBox?
    A: Use the textBox.getParent() property. It returns the parent Shape object, allowing you to access shape‑level properties or navigate to the linked shape.

  3. Q: How can I determine whether a TextBox is the head, middle, or tail of a linked sequence?
    A: Use getNext() and getPrevious(): the head has a next text box but no previous one, a middle text box has both, and the tail has a previous text box but no next one. The code example above shows these checks.

  4. Q: How do I break a forward link from a TextBox?
    A: Invoke textBox.breakForwardLink(). This removes the link to the next text box in the sequence, leaving the current box isolated.

  5. Q: Can I link a TextBox to a shape that is not a TextBox?
    A: No. Linking is only supported between TextBox objects. Attempting to link to other shape types will cause isValidLinkTarget to return false and the link operation will be ignored.