• Adding Buttons to the Viewer Control


    Adding Buttons to the Viewer Control

    This sample project demonstrates how to customize the viewer control by adding additional buttons and icons. After adding these buttons, special functions such as exporting or exiting the project, can be set up to run when the buttons are clicked.

    1. Start a new Visual Basic standard EXE project.
    2. Set Form1's properties as follows:
      Name frmViewer
      BorderStyle 1-Fixed Single
      Height 8310
      Width 13440
    3. Select the ActiveX Viewer Control from VB's component list and add the viewer control to frmViewer.
    4. Select Microsoft's Common Dialog control from VB's component list and add the control to frmViewer.
    5. Set the common dialog control's name to cmndlg.
    6. Set the viewer control's properties as follows:
      Name arv
      Height 7815
      Left 120
      Top 0
      Width 13095
    7. Add the following code to the report:
          

      Private Sub addButtonsToARV()
      'Insert a splitter control
      'in the second position (after the
      'TOC button)
      arv.ToolBar.Tools.Insert 1, ""
      arv.ToolBar.Tools.Item(1).Type = 2
      arv.ToolBar.Tools.Item(1).ID = 999
      'Insert the Close botton in the
      'third position
      arv.ToolBar.Tools.Insert 2, "Close"
      arv.ToolBar.Tools.Item(2).Caption = "&Close"
      arv.ToolBar.Tools.Item(2).Tooltip = "Close Project"
      arv.ToolBar.Tools.Item(2).ID = 1000
      'Insert another splitter in the
      'fourth position
      arv.ToolBar.Tools.Insert 3, ""
      arv.ToolBar.Tools.Item(3).Type = 2
      arv.ToolBar.Tools.Item(3).ID = 1001
      'Insert the Open button in the
      'fifth position and assign it
      'and icon
      arv.ToolBar.Tools.Insert 4, "O&pen"
      arv.ToolBar.Tools.Item(4).AddIcon LoadPicture("C:\Program Files\Microsoft _
      Visual Studio\Common\Graphics\Icons\Win95\openfold.ico")
      arv.ToolBar.Tools.Item(4).Tooltip = "Open RDF File"
      arv.ToolBar.Tools.Item(4).ID = 1002
      'Insert the Save button in the sixth
      'position and assign it an icon and
      'disable it
      arv.ToolBar.Tools.Insert 5, "&Save"
      arv.ToolBar.Tools.Item(5).AddIcon LoadPicture("C:\Program Files\Data _
      Dynamics\ActiveReports Pro\Samples\Professional Edition\Diamond Reports_
      \res\Standard\tfsave.ico")
      arv.ToolBar.Tools.Item(5).Tooltip = "Save Report to RDF"
      arv.ToolBar.Tools.Item(5).Enabled = False
      arv.ToolBar.Tools.Item(5).ID = 1003
      'Add the PDF export button to the
      'end of the toolbar and disable it
      arv.ToolBar.Tools.AddEx("&PDF").Tooltip = "Export To PDF"
      arv.ToolBar.Tools.Item(arv.ToolBar.Tools.Count - 1).Enabled = False
      arv.ToolBar.Tools.Item(arv.toolbar.tools.count-1).ID = 1004
      End Sub

    8. Add the following code to the Form_Load event:
          

      Private Sub Form_Load()
      addButtonsToARV
      End Sub

    9. Add the following code to the arv_ToolbarClick event:
          

      Private Sub arv_ToolbarClick(ByVal Tool As DDActiveReportsViewer2Ctl.DDTool)
      Select Case Tool.Caption
      Case Is = "O&pen"
      'Call the open sub
      tbOpen
      Case Is = "&Close"
      'call the exit sub
      tbExit
      Case Is = "&PDF"
      'call the PDFExport sub
      tbPDFExport
      Case Is = "&Save"
      'call the Save sub
      tbSave
      End Select
      End Sub

    10. Add the following subs to handle the click events:
          

      Private Sub tbExit()
      Unload Me
      End Sub

      Private Sub tbOpen()
      cmndlg.Filter = "Report Document File (*.rdf)|*.rdf"
      cmndlg.ShowOpen
      If cmndlg.FileName <> "" Then
      If Not arv.ReportSource Is Nothing Then
      Set arv.ReportSource = Nothing
      End If
      arv.Pages.Load cmndlg.FileName
      'Enables buttons when a report is loaded
      arv.ToolBar.Tools.Item(5).Enabled = True
      arv.ToolBar.Tools.Item(arv.ToolBar.Tools.Count - 1).Enabled = True
      End If

      End Sub

      Private Sub tbPDFExport()
      Dim pdf As New ActiveReportsPDFExport.ARExportPDF
      Set pdf = New ActiveReportsPDFExport.ARExportPDF
      cmndlg.Filter = "Portable Document Format" & _
      " (*.pdf)|*.pdf"
      cmndlg.DefaultExt = ".pdf"
      cmndlg.ShowSave
      If cmndlg.FileName <> "" Then
      pdf.FileName = cmndlg.FileName
      If Not arv.ReportSource Is Nothing Then
      pdf.Export arv.ReportSource.Pages
      Else
      pdf.Export arv.Pages
      End If
      End If
      End Sub

      Private Sub tbSave()
      cmndlg.Filter = "Report Document File (*.rdf)|*.rdf"
      cmndlg.DefaultExt = ".rdf"
      cmndlg.ShowSave
      If cmndlg.FileName <> "" Then
      If Not arv.ReportSource Is Nothing Then
      arv.ReportSource.Pages.Save _
      cmndlg.FileName
      Else
      arv.Pages.Save cmndlg.FileName
      End If
      End If
      End Sub

      Warning: Setting the viewer's ReportSource = nothing while the report is still running does not cancel the report. If the ReportSource is set to nothing while the report is running, the viewer retains the pages already processed, and the table of contents does not work. To clear the viewer use .Pages.RemoveAll and then .Pages.Commit.

    11. Save the project and run it.
  • 相关阅读:
    WPF在XAML的资源中定义空字符串String.Empty
    WPF中定义TabItem的可选区域(特别是当使用Label来呈现Header时)
    反转ListBox的ListBoxItem(控件级别,不是数据的反转)
    WPF获取相对位置、坐标的方法
    WPF为ItemsControl设置ItemsPanelTemplate
    WPF中List的Add()与Insert()方法的区别
    返回表达式列表中最小值least(exp1,exp2,exp3,……,expn)
    oracle_基本SQL语言
    JS 实现的浏览器系统通知 iNotify.js
    RHCE认证考前辅导
  • 原文地址:https://www.cnblogs.com/si812cn/p/1486196.html
Copyright © 2020-2023  润新知