I would like to connect 2 ovals with an arrow. It would be greate if in the case of moving one of the oval the arrow would follow the ovals. In my case that does not happen. Here is my code I use for making two ovals:
public async Task WriteAsync()
{
var text = "Example text in the text box";
Paragraph para = new Paragraph();
Run run = new Run();
run.AppendChild(new Text("Here is an oval:"));
para.AppendChild(run);
body.AppendChild(para);
var ovalHeight = 61;
var ovalWidth = 112;
var oval1leftMargin = 0;
var oval1topMargin = 50;
Oval oval = new Oval()
{
Id="oval1",
Style = $"position:absolute;width:{ovalWidth}pt;height:{ovalHeight}pt;margin-left:{oval1leftMargin}pt;margin-top:{oval1topMargin}pt;visibility:visible",
FillColor="white",
StrokeColor="black"
};
TextBox ovalTextBox = new TextBox();
TextBoxContent textBoxContent = new TextBoxContent();
Paragraph paragraphInOval = new Paragraph();
Run runInOval = new Run();
Text textInOval = new Text(text);
runInOval.AppendChild(textInOval);
paragraphInOval.AppendChild(runInOval);
textBoxContent.AppendChild(paragraphInOval);
ovalTextBox.AppendChild(textBoxContent);
oval.AppendChild(ovalTextBox);
var oval2leftMargin = 240;
var oval2topMargin = 20;
Oval oval2 = new Oval()
{
Id = "oval2",
Style = $"position:absolute;width:{ovalWidth}pt;height:{ovalHeight}pt;margin-left:{oval2leftMargin}pt;margin-top:{oval2topMargin}pt;visibility:visible",
FillColor = "white",
StrokeColor = "black"
};
Line line = new Line()
{
Id = "line1",
From = "oval1",
To = "oval2",
ConnectorType = ConnectorValues.Straight,
Style = "visibility:visible",
StrokeWeight = "1pt",
StrokeColor = "black",
};
Picture picture = new Picture();
picture.AppendChild(oval);
picture.AppendChild(oval2);
picture.AppendChild(line);
Paragraph paragraphWithOval = new Paragraph();
Run runwithPicture = new Run();
runwithPicture.AppendChild(picture);
paragraphWithOval.AppendChild(runwithPicture);
body.AppendChild(paragraphWithOval);
mainDocumentPart.Document.Save();
}
public void Dispose()
{
wordprocessingDocument?.Dispose();
}
Here is the result of that:
Two ovals and the line
I tried using canvas, but it broke completly the word document.
How can I make this happen?