TextBox Object

Hi
How could I change line style of a TexxtBox object?
Thanks
Mwhdi Mokhtari

Hi
Thanks for your inquiry. You should use Stroke property of Shape. For example see the following code.

// Create a new document
Document doc = new Document();
// Create TextBox
Shape textBox = new Shape(doc, ShapeType.TextBox);
// Set size of TextBox
textBox.Width = 100;
textBox.Height = 100;
//Set borders line style
textBox.Stroke.LineStyle = ShapeLineStyle.Double;
//Set borders weight
textBox.Stroke.Weight = 5;
//Set borders collor
textBox.Stroke.Color = Color.Red;
// Create Paragraph and run
Run run = new Run(doc, "TextBox with borders");
Paragraph par = new Paragraph(doc);
par.AppendChild(run);
// Insert Paragraph into the TextBox
textBox.AppendChild(par);
// Insert TextBox into the document
doc.FirstSection.Body.FirstParagraph.AppendChild(textBox);
// Save document
doc.Save(@"Test003\out.doc");

I hope this could help you.
Best regards.

Hi Alexey!
I tryed the code you posted to add a textbox into a word document but not works. The textbox not appears. Why this code not works? Any idea? Thanks!!!

// Create a new document
Document doc = new Document(@"C:\Prueba_Etiq.doc");
// Create TextBox
Shape textBox = new Shape(doc, ShapeType.TextBox);
// Set size of TextBox
textBox.Width = 100;
textBox.Height = 100;
// Set borders line style
textBox.Stroke.LineStyle = ShapeLineStyle.Double;
// Set borders weight
textBox.Stroke.Weight = 5;
// Set borders collor
textBox.Stroke.Color = Color.Red;
// Create Paragraph and run
Run run = new Run(doc, "TextBox with borders");
Paragraph par = new Paragraph(doc);
par.AppendChild(run);
// Insert Paragraph into the TextBox
textBox.AppendChild(par);
// Insert TextBox into the document
doc.FirstSection.Body.FirstParagraph.AppendChild(textBox);
// Save document
doc.Save(@"C:\Prueba_Etiq.doc");

Alexey, i found that when the document is new, it works OK,

Document doc = new Document();

but when i open a existing document, not works. The problem could be when add paragraph to document? Why is wrong?

Document doc = new Document(@"C:\pruebas.doc");

Hi

Thanks for your request. Could you please attach this document here? I will check the issue and provide you more information.
Best regards.

Hi Alexey, i attach you the file example.
No works with this file but if you create a document with MS WORD, no works too.
Only works when you create a new document with Aspose.
I hope your answeer, thanks again :wink:

Hi

Thanks for your request. Code works fine on my side and TetxBox is created properly. Also, I see at least seven the same Textboxes in the document you have attached. Cannot you see them in MS Word?
Best regards.

Hi Alexey,
Not, i can not see any of them on my MS Word. The document has seven because i was doing tests and i can not see any :frowning:
But, if on code snippet i replace

Aspose.Words.Document doc = new Aspose.Words.Document(@"C:\Pruebas.doc");

by

Aspose.Words.Document doc = new Aspose.Words.Document();
doc.Save(@"Output.doc");

and save it with another file name, it seems works fine because i can see the textbox (but the document is empty, not has words, paragraphs,…).

Hi

Thank you for additional information. Just View/Print Layout in MS Word. Then you will be able to see the shapes. Or just set doc.ViewOptions.ViewType as shown below:

Document doc = new Document(@"Test001\Prueba.doc");
doc.ViewOptions.ViewType = ViewType.PageLayout;
doc.Save(@"Test001\out.doc");

Best regards.