问题
Does anyone know a way of how to trigger the controls inside a ReportViewer(VS2005) Toolbar? I'm specifically interested in creating two buttons which I can click to go forward and backwards in the displayed report. I know that the default toolbar gives me this functionality, but the size of the forward and backwards buttons are too small for a touchscreen. This is why I thought about adding two custom buttons, that could be able to trigger the same events that the toolbar's forward and backwards buttons invoke. Thanks.
回答1:
This is an example in VB.NET how to edit the toolbar of the ReportViewer component, like adding images to dropdown items or anything you like:
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
来源:https://stackoverflow.com/questions/9070953/programmatically-trigger-reportviewer-toolbar-controls