很多时候,用户希望在C1PrintDocument中插入新页,他们不知道该使用StartDoc-EndDoc还是使用Generate方法,或者两者都使用。
C1PrintDocument的创建既可以使用StartDoc-EndDoc也使用Generate方法。这两者是相似的,但是在实现上有所区别。
在本文中,我们讨论创建documents和插入新页的两种方式。
StartDoc()-EndDoc() 方法
StartDoc方法标记document 产生的开始,在EndDoc方法标记document产生的结束。如果要用StartDoc-EndDoc 方法,render objects需要被添加到document的块中。例如:使用RenderBlock(), RenderDirect() 和RenderInline() 方法,如下所示:
c1PrintDocument1.RenderBlock(renderTable1);
Generate() Method
Generate方法使用RefreshCalculatedValues刷新模式产生document。
如果要用Generate方法,需要直接添加render objects到document的body。代码如下所示:
this.c1PrintDocument1.Body.Children.Add(new C1.C1Preview.RenderText("Hello, World!"));
虽然上述两种方法都调用来产生文档,他们不必一起使用。如果使用StartDoc,文档已经准备开始产生,这个时候不可能再去调用Generate方法刷新或是重写产生文档。
如何使用这些方法插入新页?
1。比如,你使用Generate()方法产生文档就需要在一个已经添加到文档的Render对象之前或之后插入页。例如,如下代码片断可以在两个Render Tables之间插入新页:
c1PrintDocument1..Body.Children.Add(renderTable1); rt1.BreakAfter = BreakEnum.Page; c1PrintDocument1.Body.Children.Add(renderTable2); c1PrintDocument1.Generate();
2。当使用StartDoc-EndDoc方法,可以使用C1PrintDocument的NewPage方法很容易的添加新页。代码参考如下:
c1PrintDocument1.RenderBlock(renderTable1); c1PrintDocument1.NewPage(); c1PrintDocument1.RenderBlock(renderTable2);
在Demo中有详细的代码,具体附件如下:
C1PrintDocument_NewPage2.zip (53.44 kb)
C1PrintDocument属于C1Report下的接口。如果你对它感兴趣,请到我们的官网下载最新版本:/developer/componentone-winform/controls/reports
如果你有疑问,可以到GCDN论坛获得技术支持:http://gcdn.grapecity.com.cn/showforum-68.html