2012-01-30 79 views
1

有谁知道如何触发ReportViewer(VS2005)工具栏内的控件? 我特别感兴趣的是创建两个按钮,我可以点击在显示的报告中前进和后退。我知道默认的工具栏为我提供了这种功能,但向前和向后按钮的大小对于触摸屏来说太小了。这就是为什么我想添加两个自定义按钮,可以触发与工具栏的向前和向后按钮调用相同的事件。 谢谢。以编程方式触发ReportViewer工具栏控件

回答

0

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

我非常抱歉,我忘了提,我是C#开发人员,也是VB.NET开发人员。我欣赏帮助。 – 2012-01-30 22:00:20

+0

所以你知道这两种语言,C#和VB.NET?但是没关系,你可以从这个例子中明白这一点,只需要添加:exportButton.PerformClick()来触发工具栏中的按钮。 – pistipanko 2012-01-30 22:14:32

相关问题