使形状始终保持在第一页上 [英] Make shape stay always on first page

查看:81
本文介绍了使形状始终保持在第一页上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Word开发VSTO应用程序加载项,并希望使形状始终固定在首页上.有没有办法在不主动监视形状状态的情况下做到这一点?

I am developing VSTO application add-in for Word and want to make shape be always on first page on fixed position. Is there a way to do this without actively monitoring state of a shape?

也欢迎表示无法完成"并附有解释理由的答案.

Answers that state "it can't be done" with good why explanation, are also welcome.

推荐答案

如果将形状放在页眉上并检查DifferentFirstPageHeaderFooter,分页符将不会有效,但是形状将在背景上,并且页面布局>中断>下一页将形状复制到下一页.

If you put your shape to header and check DifferentFirstPageHeaderFooter, page break do not have effect as you need, but the shape will be on background and Page Layout > Breaks > Next Page duplicate the shape to the next page.

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        AddFixedShapeOnFistPage(Application.Documents.Add(System.Type.Missing), MsoAutoShapeType.msoShapeRectangle, 160, 160, 30, 30);
    }

    public void AddFixedShapeOnFistPage(Microsoft.Office.Interop.Word.Document wordDocument, Microsoft.Office.Core.MsoAutoShapeType shapeType,int left, int top, int width, int height)
    {
        int wordTrueConst = -1; //https://social.msdn.microsoft.com/Forums/office/en-US/e9f963a9-18e4-459a-a588-17824bd3906d/differentfirstpageheaderfooter-bool-or-int?forum=worddev
        wordDocument.Sections[1].PageSetup.DifferentFirstPageHeaderFooter = wordTrueConst;
        wordDocument.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterFirstPage].Shapes.AddShape((int)shapeType, left, top, width, height);
    }

形状将在背景中

这篇关于使形状始终保持在第一页上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆