ActiveReports 报表:自定义打印

发布时间:2014/11/03 00:11 发布者:iceman

返回博客中心

ActiveReports 报表 控件可以灵活的控制打印设置,本篇文章中我们将介绍以下内容:

  • 直接打印报表
  • 设置默认打印对话框
  • 使用自定义打印对话框

下面,让我们来一一阐述实现方法:

直接打印报表

很多用户为了简化最终用户操作,希望直接打印报表,而不弹出打印设置对话框,针对这种情况下ActiveReports可以使用代码设置打印选项,为了避免用户点击工具条中的按钮而误操作,所以需要隐藏工具条中打印相关的按钮。以下是实现代码:

'Hiding the default print button
Viewer1.Toolbar.ToolStrip.Items(2).Visible = False  '2 is the index of the PrintButton in the ToolStrip
  
'Setting the custom Printer Settings
'Option 1 :
Viewer1.Document.Printer.PrinterName = "Microsoft XPS Document Writer"
Viewer1.Document.Printer.Landscape = True
Viewer1.Document.Print(False, False)
  
'Option 2 :
Report1.Document.Printer.PrinterName = "Microsoft XPS Document Writer" 'give the desired printer name
Report1.Document.Printer.Landscape = True
Report1.Document.Print(False, False)

 

传递打印设置到默认打印对话框

这也是一种常见的用户使用场景,有些用户希望弹出打印设置对话框,并且希望对话框默认显示自定义设置。针对这种情况,我们不需要隐藏打印按钮,使用以下代码传递打印机设置:

'Option 1 :
Viewer1.Document.Printer.PrinterSettings.PrinterName = "Microsoft XPS Document Writer" 'give the desired printer name
Viewer1.Document.Printer.Landscape = True
  
'Option 2 :
Report1.Document.Printer.PrinterSettings.PrinterName = "Microsoft XPS Document Writer" 'give the desired printer name
Report1.Document.Printer.Landscape = True

 

使用自定义打印对话框

这种使用场景最简单的实现方法是,隐藏默认打印按钮,添加自定义按钮到工具条中,并添加点击事件用于调用自定义打印对话框。实现代码如下:

'Replacing the default Print Button
Viewer1.Toolbar.ToolStrip.Items(2).Visible = False
Dim prnt_btn As New ToolStripButton
prnt_ btn.Image = Image.FromFile("..\..\Print.jpg")
AddHandler btn.Click, AddressOf test
Viewer1.Toolbar.ToolStrip.Items.Insert(2, prnt_btn)
  
'Assign custom properties
If Me.PrintDialog1.ShowDialog() = DialogResult.OK Then
  
'Option 1 :
Viewer1.Document.Printer.PrinterSettings = Me.PrintDialog1.PrinterSettings
Viewer1.Document.Print(False, False)
  
'Option 2 :
Report1.Document.Printer.PrinterSettings = Me.PrintDialog1.PrinterSettings
Report1.Document.Print(False, False)

 

下载示例:

VS2010 + VB.NET + AR8 + .NET4.0

 

更多ActiveReports报表功能请参考:/developer/activereports


关于葡萄城

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

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