Working with 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.
Create A Link
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:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(); | |
System::SharedPtr<Shape> shape1 = System::MakeObject<Shape>(doc, ShapeType::TextBox); | |
System::SharedPtr<Shape> shape2 = System::MakeObject<Shape>(doc, ShapeType::TextBox); | |
System::SharedPtr<TextBox> textBox1 = shape1->get_TextBox(); | |
System::SharedPtr<TextBox> textBox2 = shape2->get_TextBox(); | |
if (textBox1->IsValidLinkTarget(textBox2)) | |
{ | |
textBox1->set_Next(textBox2); | |
} |
Check TextBox Sequence
There are several ways to display text in a shape. The TextBox 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:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(); | |
System::SharedPtr<Shape> shape = System::MakeObject<Shape>(doc, ShapeType::TextBox); | |
System::SharedPtr<TextBox> textBox = shape->get_TextBox(); | |
if ((textBox->get_Next() != nullptr) && (textBox->get_Previous() == nullptr)) | |
{ | |
std::cout << "The head of the sequence" << std::endl; | |
} | |
if ((textBox->get_Next() != nullptr) && (textBox->get_Previous() != nullptr)) | |
{ | |
std::cout << "The Middle of the sequence." << std::endl; | |
} | |
if ((textBox->get_Next() == nullptr) && (textBox->get_Previous() != nullptr)) | |
{ | |
std::cout << "The Tail of the sequence." << std::endl; | |
} |
Break a Link
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:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(); | |
System::SharedPtr<Shape> shape = System::MakeObject<Shape>(doc, ShapeType::TextBox); | |
System::SharedPtr<TextBox> textBox = shape->get_TextBox(); | |
// Break a forward link | |
textBox->BreakForwardLink(); | |
// Break a forward link by setting a null | |
textBox->set_Next(nullptr); | |
// Break a link, which leads to this textbox | |
if (textBox->get_Previous() != nullptr) | |
{ | |
textBox->get_Previous()->BreakForwardLink(); | |
} |