Studio for WinForms:C1Report 定制展示和打印页面大小

发布时间:2014/06/18 00:06 发布者:iceman

返回博客中心

 

C1Report 允许我们按照实际需求,定制页面大小生成和打印报表,默认情况下报表的大小为A4。但是,有时为了适应打印机中纸张大小需要调整报表的页面大小。本篇文章阐述了定制报表中页面大小和打印纸张大小的方法。

定制报表页面大小

定制页面大小可以通过以下两种方式:

  • 设置 C1Report Document‘DefaultPageSettings.PaperSize’ 属性
  • 设置 C1Report ‘Layout.Papersize’ 属性

C1Report:

以下是设置 C1Report’s papersize 属性的步骤:
1. 设置Set the ‘Layout.PaperSize‘ property to ‘PaperKind.Custom’。
2.通过‘Layout.CustomHeight’‘Layout.CustomWidth’ 属性定制 C1Report 大小。

Code

C1Report1.Layout.PaperSize = PaperKind.Custom
C1Report1.Layout.CustomHeight = " "
C1Report1.Layout.CustomWidth = " "

C1PrintDocument:

以下是设置 C1PrintDocument 页面大小的步骤:
1. 创建 C1PrintDocument 实例。
2. 创建 ‘PaperSize’ 实例,并且设置自定义的宽和高。
3. 赋值给 DefaultPageSettings.PaperSize 属性。

Dim PrintDoc As New PrintDocument
Dim cps As New PaperSize
PrintDoc = C1Report1.Document
cps = New PaperSize("MyCustomPaperSize", "CustomHeight", "CustomWidth")
PrintDoc.DefaultPageSettings.PaperSize = cps

 

定制打印页面大小

 

很多用户反馈在使用不同打印机打印报表时,由于不同的打印机设置经常会遇到报表大小和纸张大小不一致的情况。这里我们就来实现一下如何自适应打印机页面设置。

我们需要通过自定义打印对话框来实现,打印对话框通过点击 C1PrintPreviewControl Print 按钮调用。

步骤:
1. 删除 C1PrintPreviewControl 工具条中的 Print 按钮。
2. 添加自定义 Print 按钮到 C1PrintPreviewControl 中。你可以参考链接中的步骤实现:
Adding Custom Button Preview Controls
3. 通过Print按钮的点击事件调用自定义打印对话框,设置打印对话框的 PrinterSetting属性为 C1Document 的PrinterSettings 属性。
4. 调用打印对话框
5. 最后打印报表

Code:

C1Report:

Dim pd As PrintDialog = New PrintDialog()
pd.PrinterSettings = C1Report1.Document.PrinterSettings
If pd.ShowDialog() = DialogResult.OK Then
C1Report1.Document.Print()
End If

C1PrintDocument:

Dim pd As PrintDialog = New PrintDialog()
pd.PrinterSettings = PrintDoc.PrinterSettings
If pd.ShowDialog() = DialogResult.OK Then
PrintDoc.Print()
End If

 

通过以上方法输入页面高为 500 宽为 650. Implementation is given in the attached sample.

Demo 下载:

VS2010 + Framework 4.0 + VB.NET


关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网