C1PrintDocument基于页面大小生成

一般来说,当记录是在c1printdocument描绘,他们根据调整页面大小计算,如果没有可用的页面空间,描绘的内容是按页面进行拆分。在本文中,我们讨论在C1PrintDocument的可用的页面上,如何定位数据。这种方法可以由用户决定如何在页面的位置显示一组记录,而不是单纯的按页面进行拆分记录。步骤如下:1.使用StartDoc方法创建一个新的C1PrintDocment。2.添加需要的数据,比如使用RenderBlock方法添加一个RenderTable到C1PrintDocment。3.现在,使用C1PrintDocument类的AvailableBlockFlowHeight属性,在当前的页面区域设置垂直的一块区域。4.基于AvailableBlockFlowHeight的返回值,决定是否请求文字,例如RenderText,应该从当前页面绘制还是在他们之间应该隔开。新页可以使用C1PrintDocument类的NewPage方法插入。

发布于 2014/07/26 00:00

ComponentOne Enterprise

一般来说,当记录是在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代码:

C1Report_AvailableBlockFlowHeight_CSharp.zip (17.17 kb)

ComponentOne Enterprise | 下载试用

ComponentOne 是一套专注于企业 .NET开发、支持 .NET Core 平台,并完美集成于 Visual Studio 的第三方控件集,包含 300 多种 .NET开发控件,提供表格数据管理、数据可视化、报表和文档、日程安排、输入和编辑、导航和布局、系统提升工具等七大功能,被誉为“.NET开发的‘瑞士军刀’”。

ComponentOne 为您提供专业的产品咨询服务,并由技术支持工程师为您1对1解答。>> 发帖提问

相关产品
推荐相关案例
关注微信
葡萄城社区二维码

关注“葡萄城社区”

加微信获取技术资讯

加微信获取技术资讯

想了解更多信息,请联系我们, 随时掌握技术资源和产品动态