一般来说,当记录是在c1printdocument描绘,他们根据调整页面大小计算,如果没有可用的页面空间,描绘的内容是按页面进行拆分。
在本文中,我们讨论在C1PrintDocument的可用的页面上,如何定位数据。这种方法可以由用户决定如何在页面的位置显示一组记录,而不是单纯的按页面进行拆分记录。
步骤如下:
1.使用StartDoc方法创建一个新的C1PrintDocment。
2.添加需要的数据,比如使用RenderBlock方法添加一个RenderTable到C1PrintDocment。
3.现在,使用C1PrintDocument类的AvailableBlockFlowHeight属性,在当前的页面区域设置垂直的一块区域。
4.基于AvailableBlockFlowHeight的返回值,决定是否请求文字,例如RenderText,应该从当前页面绘制还是在他们之间应该隔开。新页可以使用C1PrintDocument类的NewPage方法插入。
参考代码如下:
private void Form1_Load(object sender, EventArgs e)
{
this.c1PrintDocument1.ResolvedUnit = UnitTypeEnum.Twip;
this.c1PrintDocument1.DefaultUnit = UnitTypeEnum.Twip;
c1PrintDocument1.AllowNonReflowableDocs = true;
this.c1PrintDocument1.StartDoc();
C1.C1Preview.RenderTable rt1 = new C1.C1Preview.RenderTable();
C1.C1Preview.RenderText rt2 = new C1.C1Preview.RenderText();
int row = 0;
int col = 0;
while ((row < 100))
{
col = 0;
while ((col < 3))
{
rt1.Cells[row, col].Text = string.Format("Text in cell({0},{1})", row, col);
rt1.Cells[row, col].Style.Borders.All = new LineDef(Color.Black);
col += 1;
}
row += 1;
}
rt1.Style.Borders.All = new LineDef(Color.Black);
col = 0;
while ((col < 3))
{
rt1.Cols[col].Width = "1in";
col += 1;
}
rt2.Text = "This is the text whose position is to be decided";
rt2.Style.TextColor = Color.Red;
c1PrintDocument1.RenderBlock(rt1);
MessageBox.Show("Avaialable Height : " + this.c1PrintDocument1.AvailableBlockFlowHeight.ToString());
RenderText rs = new RenderText();
rs.Text = "test";
double d = c1PrintDocument1.AvailableBlockFlowHeight;
if (d > 3000)
{
}
else
{
c1PrintDocument1.NewPage();
}
c1PrintDocument1.RenderBlock(rt2);
this.c1PrintDocument1.EndDoc();
c1PrintPreviewControl1.Document = c1PrintDocument1;
}
请注意:在使用StartDoc()/EndDoc()方法产生document的时候,AvailableBlockFlowHeight属性才会起作用。
本文Demo代码: