mindrayguowei 发表于 2016-6-3 10:00:51

TextControl如何在文档结尾添加一页空白页并取得页码?

如题

gw0506 发表于 2016-6-7 16:35:25

非常抱歉,这个帖子应该是我的原因漏掉了。耽误了这么久。送你300金币以表歉意。
这个需求就是Pages里Add一个新的page。
至于插入footer的页码,文档有提到,参考下面代码:
HeaderFooterCollection hfc = textControl1.Sections.GetItem().HeadersAndFooters;

hfc.Add(HeaderFooterType.Header);

HeaderFooter h = hfc.GetItem(HeaderFooterType.Header);
if (h != null)
{
        h.Selection.Text = "Pageof ";
        h.Selection.Start = 5;
        h.Selection.Length = 0;

        PageNumberField page = new PageNumberField(1, NumberFormat.ArabicNumbers);
        page.Editable = false;
        page.DoubledInputPosition = true;
        h.PageNumberFields.Add(page);

        h.Selection.Start = 9;
        h.Selection.Length = 0;

        PageNumberField totalPages = new PageNumberField();
        totalPages.Editable = false;
        totalPages.DoubledInputPosition = true;
        totalPages.ShowNumberOfPages = true;
        h.PageNumberFields.Add(totalPages);
}

mindrayguowei 发表于 2016-6-7 16:55:28

不好意思, 我实在没有找到如何在Pages里Add一个新的page的代码, 你能发一段相应的代码给我吗?
另外, 我不是要插入footer的页码, 而是要获取这个新添加的一页的页码

gw0506 发表于 2016-6-7 18:32:54

本帖最后由 gw0506 于 2016-6-7 18:39 编辑

mindrayguowei 发表于 2016-6-7 16:55
不好意思, 我实在没有找到如何在Pages里Add一个新的page的代码, 你能发一段相应的代码给我吗?
另外, 我不 ...
是我不好意思才对,PageCollection的确没有暴露Add方法。有一个做法如下:            textControl1.ViewMode = TXTextControl.ViewMode.PageView;

            int newPage = this.textControl1.InputPosition.Page + 1;
            InputPosition inputPosition = new TXTextControl.InputPosition(newPage, 1, 0);

            this.textControl1.Selection.Text = "\f";
            this.textControl1.InputPosition = inputPosition;
            Point ScrollPosition = new Point(0, inputPosition.Location.Y);
            this.textControl1.ScrollLocation = ScrollPosition;
            this.textControl1.Focus();这个新加入的page的页码不就是 Count吗?我理解的对吗?如果是,那就是this.textControl1.Pages

页: [1]
查看完整版本: TextControl如何在文档结尾添加一页空白页并取得页码?