Làm việc với TextBoxes
Trong Aspose.Words, lớp TextBox được sử dụng để chỉ định cách văn bản được hiển thị bên trong một hình dạng. Nó hiển thị một thuộc tính công khai có tên Parent để có được hình dạng cha mẹ cho hộp văn bản để khách hàng có thể tìm thấy Shape được liên kết từ TextBox được liên kết.
Tạo Một Liên Kết
Lớp TextBox cung cấp phương thức IsValidLinkTarget để kiểm tra xem TextBox có thể được liên kết với mục tiêu Textbox hay không.
Ví dụ mã sau đây cho thấy cách kiểm tra xem TextBox
có thể được liên kết với hộp văn bản đích hay không:
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); | |
} |
Kiểm Tra Trình Tự TextBox
Có một số cách để hiển thị văn bản trong một hình dạng. TextBox có Thể Là Đầu, Giữa hoặc Đuôi của một chuỗi.
Ví dụ mã sau đây cho thấy cách kiểm tra xem TextBox là Đầu, Đuôi hoặc Giữa chuỗi:
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; | |
} |
Phá Vỡ Một Liên kết
Sử dụng phương thức BreakForwardLink, bạn có thể phá vỡ liên kết đến TextBox tiếp theo.
Ví dụ mã sau đây cho thấy cách phá vỡ một liên kết cho 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(); | |
} |