ActiveReports 报表:自定义打印

ActiveReports 报表控件可以灵活的控制打印设置,本篇文章中我们将介绍以下内容:直接打印报表设置默认打印对话框 使用自定义打印对话框

发布于 2014/11/03 00:00

ActiveReports

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

ActiveReports 报表控件| 下载试用

ActiveReports 是一款专注于 .NET 平台的报表控件,全面满足 HTML5 / WinForm / ASP.NET / ASP.NET MVC / WPF 等平台下报表设计和开发工作需求,作为专业的报表工具为全球超过 300,000 开发人员提供了全面的报表开发服务。

您对ActiveReports产品的任何技术问题,都有技术支持工程师提供1对1专业解答,点击此处即可发帖提问>>技术支持论坛

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

关注“葡萄城社区”

加微信获取技术资讯

加微信获取技术资讯

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