與文字方塊一起工作
在 Aspose.Words 中,TextBox 類別用於指定文字如何顯示於形狀內。 它會將名為 Parent 的公共屬性公開,以取得文字方塊的父體,以便客戶可以從關聯的 TextBox 中找到連結的 Shape。
建立一個連結
TextBox類別提供了IsValidLinkTarget方法,以便檢查是否可以將 TextBox 連接到目標 Textbox。
接下來的程式碼範例說明如何檢查是否可以將 TextBox
連結到目標文字方塊:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
Document doc = new Document(); | |
Shape shape1 = new Shape(doc, ShapeType.TextBox); | |
Shape shape2 = new Shape(doc, ShapeType.TextBox); | |
TextBox textBox1 = shape1.TextBox; | |
TextBox textBox2 = shape2.TextBox; | |
if (textBox1.IsValidLinkTarget(textBox2)) | |
textBox1.Next = textBox2; |
檢查Текст框序列
有幾種在形狀中顯示文字的方法。 這個 TextBox 可以是序列的頭、中或尾。
接下來的範例說明了如何檢查 TextBox 是否為序列的頭、尾或中間:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
Document doc = new Document(); | |
Shape shape = new Shape(doc, ShapeType.TextBox); | |
TextBox textBox = shape.TextBox; | |
if ((textBox.Next != null) && (textBox.Previous == null)) | |
{ | |
Console.WriteLine("The head of the sequence"); | |
} | |
if ((textBox.Next != null) && (textBox.Previous != null)) | |
{ | |
Console.WriteLine("The Middle of the sequence."); | |
} | |
if ((textBox.Next == null) && (textBox.Previous != null)) | |
{ | |
Console.WriteLine("The Tail of the sequence."); | |
} |
打破一個連結
使用 BreakForwardLink 這個方法,你可以中斷連結到下一個 TextBox。
以下範例說明如何打破一個連結,使之以 TextBox 結束。
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
Document doc = new Document(); | |
Shape shape = new Shape(doc, ShapeType.TextBox); | |
TextBox textBox = shape.TextBox; | |
// Break a forward link | |
textBox.BreakForwardLink(); | |
// Break a forward link by setting a null | |
textBox.Next = null; | |
// Break a link, which leads to this textbox | |
if (textBox.Previous != null) | |
textBox.Previous.BreakForwardLink(); |