Praca z TextBoxami
W Aspose.Words klasa TextBox służy do określenia sposobu wyświetlania tekstu wewnątrz kształtu. Udostępnia publiczną właściwość o nazwie Parent, aby uzyskać kształt nadrzędny pola tekstowego, dzięki czemu klient może znaleźć połączony Shape z powiązanego TextBox.
Tworzenie łącza
Klasa TextBox udostępnia metodę IsValidLinkTarget w celu sprawdzenia, czy TextBox można powiązać z docelowym plikiem Textbox.
Poniższy przykład kodu pokazuje, jak sprawdzić, czy TextBox
można powiązać z docelowym polem tekstowym:
// 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; |
Sprawdź sekwencję pola tekstowego
Istnieje kilka sposobów wyświetlania tekstu w kształcie. TextBox może być głową, środkiem lub ogonem sekwencji.
Poniższy przykład kodu pokazuje, jak sprawdzić, czy TextBox jest głową, ogonem czy środkiem sekwencji:
// 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."); | |
} |
Zrywanie łącza
Za pomocą metody BreakForwardLink możesz przerwać łącze do następnego TextBox.
Poniższy przykład kodu pokazuje, jak przerwać łącze dla 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(); |