【问题标题】:Programmatically trigger ReportViewer Toolbar controls以编程方式触发 ReportViewer 工具栏控件
【发布时间】:2012-02-22 15:57:48
【问题描述】:

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

【问题讨论】:

    标签: c# visual-studio-2005 reportviewer toolbar


    【解决方案1】:

    这是 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
    

    【讨论】:

    • 非常抱歉,我忘记提及我是 C# 开发人员和 VB.NET 开发人员。不过,我感谢您的帮助。
    • 那么您了解 C# 和 VB.NET 这两种语言吗?不过没关系,从这个例子中你就可以理解重点了,只要加上这个:exportButton.PerformClick()就可以触发工具栏中的按钮了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多