2012-01-30 78 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

相關問題