在MS Word中提供了一种特殊的域类型,通过该类型的域和现实文档的页号和总页数,这些域可以插入到页眉或者页脚中,TX Text Control也支持这样的特殊域类型。
TX Text Control中通过PageNumberField来对当前页的页号提供支持,而文档的总页数被封装在ApplicationField类型中,PageNumberField的使用方法如下:- TXTextControl.PageNumberField pageNumberField =
- new TXTextControl.PageNumberField(1,
- TXTextControl.NumberFormat.ArabicNumbers);
-
- TXTextControl.HeaderFooter newHeader =
- textControl1.Sections.GetItem().HeadersAndFooters.GetItem(TXTextControl.HeaderFooterType.Header);
- newHeader.PageNumberFields.Add(pageNumberField);
复制代码 文档中每页的页号信息会自动更新,总页数信息需要通过当前文档的页数来动态设置,下面代码演示了如何动态更新页眉和页脚中显示的总页数信息:- private void updateNumPagesField()
- {
- // iterate through all sections
- foreach (TXTextControl.Section curSection in textControl1.Sections)
- {
- // iterate through all headers and footers of the sections
- foreach (TXTextControl.HeaderFooter curHeader in curSection.HeadersAndFooters)
- {
- // iterate through all application fields
- foreach (TXTextControl.ApplicationField curField in curHeader.ApplicationFields)
- {
- // if NUMPAGES is found, update the text property
- // with the current number of pages
- if (curField.TypeName == "NUMPAGES")
- {
- curField.Text = textControl1.Pages.ToString();
- }
- }
- }
- }
- }
复制代码
png
源码:VS2010 + TX TextControl 17.0
page_number.zip
(14.4 KB, 下载次数: 990)
|
|