ActiveReports中自定义Winforms的Viewer 工具栏

ActiveReports中提供不同平台的报表浏览器来加载报表,而不同平台的报表浏览器功能也不一致,今天我们来学习如何定制Winforms Viewer控件。

预览效果:

Shows a run-time view of the custom print button showing the tooltip text.

 

核心代码:

C#

// C#

private ToolStripButton tsbPrint = new System.Windows.Forms.ToolStripButton();

private void frmViewer_Load(object sender, EventArgs e) { System.Windows.Forms.ToolStrip toolStrip; System.Windows.Forms.ToolStripItem orgItem; System.Windows.Forms.ToolStripButton orgBtn = null; // Get the image from the standard Print button. toolStrip = this.viewer1.Toolbar.ToolStrip; orgItem = toolStrip.Items[2]; if (orgItem is System.Windows.Forms.ToolStripButton) { orgBtn = (System.Windows.Forms.ToolStripButton)orgItem; } // Delete the standard Print button. toolStrip.Items.RemoveAt(2); // Create a custom button to use in place of the standard Print button. tsbPrint.Text = “HQ Print”; tsbPrint.ToolTipText = “Print to the company headquarters main printer”; tsbPrint.Image = orgBtn.Image; tsbPrint.Enabled = false; // Set the event handler. (viewer.LoadCompleted can be set from the designer) tsbPrint.Click += this.PrintButtonClick; viewer1.LoadCompleted += this.viewer1_LoadCompleted; // Add the custom button to the toolbar. toolStrip.Items.Insert(2, tsbPrint); // Instantiate the report. GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport(); // Load a report definition file. rpt.Load(new System.IO.FileInfo(@”..\..\PageReport1.rdlx”)); GrapeCity.ActiveReports.Document.PageDocument pageDocument = new GrapeCity.ActiveReports.Document.PageDocument(rpt); // Load the report into the viewer. viewer1.LoadDocument(pageDocument); } // The event to call when the report is loaded into the Viewer. private void viewer1_LoadCompleted(object sender, EventArgs e) { // Enable the custom button. tsbPrint.Enabled = true; } // The event to call when the custom button is clicked. private void PrintButtonClick(System.Object sender, System.EventArgs e) { // Perform print processing. this.viewer1.Print(true, true, false); }

 

VB.NET

‘ VB.NET

Private tsbPrint As New System.Windows.Forms.ToolStripButton

Private Sub frmViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim toolStrip As System.Windows.Forms.ToolStrip
        Dim orgBtn As System.Windows.Forms.ToolStripButton = Nothing
        Dim orgItem As System.Windows.Forms.ToolStripItem

        ‘ Get the image from the standard Print button.
        toolStrip = Me.Viewer1.Toolbar.ToolStrip
        orgItem = toolStrip.Items(2)
        If TypeOf orgItem Is System.Windows.Forms.ToolStripButton Then
                orgBtn = CType(orgItem, ToolStripButton)
        End If

        ‘ Delete the standard Print button.
        toolStrip.Items.RemoveAt(2)

        ‘ Create a custom button to use in place of the standard Print button.
        tsbPrint.Text = “HQ Print”
        tsbPrint.ToolTipText = “Print to the company headquarters main printer”
        tsbPrint.Image = orgBtn.Image
        tsbPrint.Enabled = False

        ‘ Set the event handler (Viewer.LoadCompleted can also be set in the designer)
        AddHandler tsbPrint.Click, AddressOf Me.PrintButtonClick
        AddHandler Viewer1.LoadCompleted, AddressOf Me.Viewer1_LoadCompleted

        ‘ Add the custom button to the toolbar.
        toolStrip.Items.Insert(2, tsbPrint)

        ‘ Instantiate the report.
        Dim rpt As New GrapeCity.ActiveReports.PageReport()

        ‘ Load a report definition file.
        rpt.Load(New System.IO.FileInfo(“..\..\PageReport1.rdlx”))
        Dim pageDocument As New GrapeCity.ActiveReports.Document.PageDocument(rpt)

        ‘ Load the report into the viewer.
        viewer1.LoadDocument(pageDocument)
End Sub

‘ The event to call when the report loads in the Viewer. Private Sub Viewer1_LoadCompleted(sender As Object, e As EventArgs) ‘ Enable the custom button. tsbPrint.Enabled = True End Sub ‘ The event to call when the custom button is clicked. Private Sub PrintButtonClick(ByVal sender As Object, ByVal e As System.EventArgs) ‘ Perform print processing. Me.Viewer1.Print(True, True, False) End Sub

转载于:https://www.cnblogs.com/lenkaguo/p/5949516.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值