我已经创建了两个形状rect1
和rect2
。我想在rect2
上方绘制rect1
。
Shape rect1 = wordDoc.Shapes.AddShape((int)Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, 10, 10, 100, 40, tempRange);
// Put components in that paragraph
rect1.TextFrame.TextRange.Text = "Arun";
rect1.TextFrame.TextRange.Font.Size = 8;
rect1.ConvertToInlineShape();
Shape rect2 = wordDoc.Shapes.AddShape((int)Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, 10, 10, 50, 20, tempRange);
// Put components in that paragraph
rect2.TextFrame.TextRange.Text = "InnerShape";
rect2.TextFrame.TextRange.Font.Size = 8;
rect2.ConvertToInlineShape();
rect2.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoBringToFront);
wordDoc.SaveAs(archDocFile, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
答案 0 :(得分:0)
将呼叫转移到ConvertToInlineShape()
。这些调用将形状从“绘图”层“移动”到“文本”层,这使得它们无法自由定位(它们变得像字符/单词/段落一样定位)。
参考:
https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.interop.word.shape.converttoinlineshape
要定位现在浮动的形状,请设置属性Top和Left(或者也许设置TopRelative和LeftRelative)。阅读文档,看看它们如何工作!