当前位置: 首页 > 编程语言 > C#

让形状始终位于首页Share

时间:2023-04-11 01:28:28 C#

让形状始终位于首页有没有办法在不主动监视形状状态的情况下做到这一点?“无法完成”的答案也欢迎解释原因。如果将形状设置为页眉并选中DifferentFirstPageHeaderFooter,则分页符不会按照您的要求进行,但形状将位于背景上,页面布局>分页>下一页会将形状复制到下一页。privatevoidThisAddIn_Startup(objectsender,System.EventArgse){AddFixedShapeOnFistPage(Application.Documents.Add(System.Type.Missing),MsoAutoShapeType.msoShapeRectangle,160,160,30,30);}publicvoidAddFixedShapeOnFistPage(Microsoft.Office.Interop.Word.DocumentwordDocument,Microsoft.Office.Core.MsoAutoShapeTypeshapeType,intleft,inttop,intwidth,intheight){intwordTrueConst=-1;//https://social.msdn.microsoft.com/Forums/office/en-US/e9f963a9-18e4-459a-a588-17824bd3906d/differentfirstpageheaderfooter-bool-or-int?forum=worddevwordDocument.Sections[1]。PageSetup.DifferentFirstPageHeaderFooter=wordTrueConst;wordDocument.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterFirstPage].Shapes.AddShape((int)shapeType,left,top,width,height);}形状将在背面是的,这是可以现实的。代码如下:usingWord=Microsoft.Office.Interop.Word;publicvoidDrawShape(){try{varwordApp=newWord.Application();wordApp.Documents.Add(System.Type.Missing);Word.Documentdoc=wordApp.ActiveDocument;varshape=doc.Shapes.AddShape((int)Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle,20,20,60,20);}catch(Exceptionex){}}上面的代码是在第一个文档中在页面左上角(位置(20,20))绘制一个宽60,高20的矩形。请记住,(0,0)是Doc文件第一页左上角的起点。在这里,Shapes.AddShape应该可以解决问题。ShapeAddShape(intType,floatLeft,floatTop,floatWidth,floatHeight,refobjectAnchor=Type.Missing);有关SHapes.AddShape()的更多信息:https://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.shapes.addshape.aspx对于不同类型的形状,请参阅MsoAutoShapeType:https://msdn.microsoft.com/en-us/library/microsoft.office.core.msoautoshapetype.aspx以上是C#学习教程:永远保持第一页的形状。分享的所有内容,如果对大家有用,需要进一步了解C#学习教程,希望大家多加关注——本文收集自网络,不代表立场,如涉及侵权,请谅解点击右侧联系管理员删除。如需转载请注明出处: