← 返回所有博客文章

从ActiveReports3/6升级到ActiveReports7之后需要重写ActiveReports3/6中自定义Viewer工具栏的代码,在ActiveReports3/6中的工具栏类型为 DataDynamics.ActiveReports.Viewer.ToolbarObject,在ActiveReports7中工具栏类型为System.Windows.Forms.ToolStrip,也就是说在ActiveReports7中使用的是 .NET 标准的 ToolStrip 控件。

1、在AR3中是在 Viewer.ToolClick 事件中判断 Tool.Id 进行相应的事件处理,AR7中时在创建自定义按钮时,直接指定该按钮的的单击事件

ActiveReports3/6代码:

Public Class Form1
     'User Guide > How-To Section > Customizing the Viewer Control
     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
         Dim rpt As New AR3()
        Me.Viewer1.Document = rpt.Document
        rpt.Run()
         '删除 Viewer 中内置的打印按钮
        Viewer1.Toolbar.Tools.RemoveAt(2)
         '创建并添加自定义的打印按钮
        Dim btn As New DataDynamics.ActiveReports.Toolbar.Button()
        btn.Caption = "自定义打印"
        btn.ToolTip = "自定义打印"
        btn.ImageIndex = 1
        btn.ButtonStyle = DataDynamics.ActiveReports.Toolbar.ButtonStyle.TextAndIcon
        btn.Id = 333
        Me.Viewer1.Toolbar.Tools.Insert(2, btn)
     End Sub
     Private Sub Viewer1_ToolClick(ByVal sender As System.Object, ByVal e As DataDynamics.ActiveReports.Toolbar.ToolClickEventArgs) Handles Viewer1.ToolClick
         ' 根据单击按钮的 Id 来判断当前点击的是否为自定义打印按钮
        If e.Tool.Id = 333 Then
            Dim dlg As New frmPrintDlg()
            dlg.ShowDialog(Me)
        End If
    End Sub
 End Class

 

ActiveReports 7 代码:

Public Class Form1
     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
         '删除 Viewer 中内置的打印按钮
        Viewer1.Toolbar.ToolStrip.Items.RemoveAt(2)
         '删除分隔符
        Viewer1.Toolbar.ToolStrip.Items.RemoveAt(1)
         '在 Viewer 工具栏中添加新的打印按钮
        Dim tsbPrint As New ToolStripButton("自定义打印")
        Viewer1.Toolbar.ToolStrip.Items.Add(tsbPrint)
         '为新添加的打印按钮指定单击事件
        AddHandler tsbPrint.Click, AddressOf tsbPrint_Click
    End Sub
     '在打印按钮的单击事件中调用打印对话框
    Private Sub tsbPrint_Click(ByVal sender As Object, ByVal e As EventArgs)
        Me.CustomPrint()
    End Sub
     '显示自定义的打印对话框
    Private Sub CustomPrint()
        Dim _printForm As New frmPrintDlg()
        _printForm.ShowDialog(Me)
    End Sub
 End Class

 

 

在AR7中我们是通过AddHandler tsbPrint.Click, AddressOf tsbPrint_Click来指定自定义按钮的单击事件,并在单击事件处理函数中实现相应的功能。

2、“Print”不是“GrapeCity.ActiveReports.Document.SectionDocument”的成员。

如果要直接调用 rpt.Document.Print() 方法,需要添加命名空间 Imports GrapeCity.ActiveReports

 

在你安装ActiveReports 7之后,可以在 C:\Users\用户名\Documents\ComponentOne Samples\ActiveReports Developer 7\Section Reports\C#\Preview\CustomPreview 找到自定义预览的源码