Move Text Box Programmatically in Word DOCX Document using C# .NET Code | Coordinates of Shape

Hi

I want to move a Textbox from one location to another.
Can you show me how?
I have attached a sample word doc which shows “Textbox A” and “Textbox B”.
So I would like “Textbox A” to be moved to where “Textbox B” is.

textbox sample.zip (15.3 KB)

@tony.woods.bell.ca,

Please use the following C# code of Aspose.Words for .NET API to move a textbox shape in Word document to another position:

Document doc = new Document("C:\\textbox sample\\textbox sample.docx");

Shape first_Shape = (Shape)doc.GetChildNodes(NodeType.Shape, true)[0]; // B Textbox
Shape second_Shape = (Shape)doc.GetChildNodes(NodeType.Shape, true)[1]; // A Textbox

// anchor Shapes to same Paragraph
first_Shape.ParentParagraph.InsertAfter(second_Shape, first_Shape);

// Get coordinates of B Textbox
LayoutCollector layoutCollector = new LayoutCollector(doc);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
layoutEnumerator.Current = layoutCollector.GetEntity(first_Shape);

// Move A Textbox to desired position
second_Shape.Left = layoutEnumerator.Rectangle.Left;
second_Shape.Top = layoutEnumerator.Rectangle.Top;
second_Shape.WrapType = WrapType.None;
second_Shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
second_Shape.RelativeVerticalPosition = RelativeVerticalPosition.Page;

doc.Save("C:\\textbox sample\\20.9.docx");

Thank you so much for the code!!