使用文本框
Contents
[
Hide
]
在 Aspose.Words 中,TextBox 类用于指定文本在形状内的显示方式。它公开一个名为 Parent 的公共属性来获取文本框的父形状,以便客户可以从关联的 TextBox 中找到链接的 Shape。
创建链接
TextBox 类提供了 IsValidLinkTarget 方法来检查 TextBox 是否可以链接到目标 Textbox。
以下代码示例显示如何检查 TextBox
是否可以链接到目标文本框:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 是序列的头、尾还是中间:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 的链接:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |