Робота з TextBoxes
Aspose.Words клас TextBox використовується для вказівки способу відображення тексту всередині фігури. Він надає загальнодоступну властивість під назвою Parent, що дозволяє отримати батьківську фігуру для текстового поля, щоб користувач міг знайти зв’язаний Shape із зв’язаного TextBox.
Створіть посилання
Клас TextBox надає метод IsValidLinkTarget, щоб перевірити, чи може TextBox бути пов’язаний з цільовим об’єктом Textbox.
Наступний приклад коду показує, як перевірити, чи можна пов’язати 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); | |
} |
Перевірте послідовність TextBox
Існує кілька способів відображення тексту у формі. Символ TextBox може бути початком, серединою або кінцем послідовності.
Наступний приклад коду показує, як перевірити, чи є 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(); | |
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; | |
} |
Розірвати зв’язок
Використовуючи метод BreakForwardLink, ви можете розірвати посилання на наступне TextBox.
Наступний приклад коду показує, як розірвати посилання для 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(); | |
} |