以编程方式触发ReportViewer工具栏控件

本文关键字:工具栏 控件 ReportViewer 编程 方式触 | 更新日期: 2023-09-27 18:22:00

有人知道如何触发ReportViewer(VS2005)工具栏中的控件吗?我特别感兴趣的是创建两个按钮,我可以单击它们在显示的报告中前进和后退。我知道默认工具栏为我提供了这一功能,但向前和向后按钮的大小对于触摸屏来说太小了。这就是我考虑添加两个自定义按钮的原因,这两个按钮可以触发工具栏的前进和后退按钮调用的相同事件。谢谢

以编程方式触发ReportViewer工具栏控件

这是VB.NET中如何编辑ReportViewer组件的工具栏的示例,例如将图像添加到下拉项或任何您喜欢的内容:

Private Sub AddImgRVToolBar()
    Dim ts As ToolStrip = Me.FindToolStrip(Of ToolStrip)(Me.ReportViewer1)
            If ts IsNot Nothing Then
                Dim exportButton As ToolStripDropDownButton = TryCast(ts.Items("export"), ToolStripDropDownButton)
                If exportButton IsNot Nothing Then
                    AddHandler exportButton.DropDownOpened, AddressOf OnExportOpened
                End If
            End If
End Sub
    Private Sub OnExportOpened(sender As Object, e As EventArgs)
            If TypeOf sender Is ToolStripDropDownButton Then
                Dim button As ToolStripDropDownButton = DirectCast(sender, ToolStripDropDownButton)
                For Each item As ToolStripItem In button.DropDownItems
                    Dim extension As RenderingExtension = DirectCast(item.Tag, RenderingExtension)
                    If extension IsNot Nothing Then
                        Select Case extension.Name
                            Case "Excel"
                                item.Image = My.Resources.page_white_excel_16x16
                            Case "PDF"
                                item.Image = My.Resources.page_white_acrobat_16x16
                            Case "WORD"
                                item.Image = My.Resources.page_white_word_16x16
                                item.Text = "Word"
                        End Select
                    End If
                Next
            End If
        End Sub
        Private Function FindToolStrip(Of T As System.Windows.Forms.Control)(ByVal control As Control) As T
            If control Is Nothing Then
                Return Nothing
            ElseIf TypeOf control Is T Then
                Return DirectCast(control, T)
            Else
                Dim result As T = Nothing
                For Each embedded As Control In control.Controls
                    If result Is Nothing Then
                        result = FindToolStrip(Of T)(embedded)
                    End If
                Next
                Return result
            End If
        End Function