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.CustomC1Report1.Layout.CustomHeight = " "
C1Report1.Layout.CustomWidth = " "
C1PrintDocument:
以下是设置 C1PrintDocument 页面大小的步骤:
1. 创建 C1PrintDocument 实例。
2. 创建 ‘PaperSize’ 实例,并且设置自定义的宽和高。
3. 赋值给 DefaultPageSettings.PaperSize 属性。
Dim PrintDoc As New PrintDocumentDim cps As New PaperSizePrintDoc = C1Report1.Documentcps = 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.PrinterSettingsIf pd.ShowDialog() = DialogResult.OK ThenC1Report1.Document.Print()End If
C1PrintDocument:
Dim pd As PrintDialog = New PrintDialog()pd.PrinterSettings = PrintDoc.PrinterSettingsIf pd.ShowDialog() = DialogResult.OK ThenPrintDoc.Print()End If
通过以上方法输入页面高为 500 宽为 650. Implementation is given in the attached sample.
Demo 下载:
VS2010 + Framework 4.0 + VB.NET