以编程方式触发 ReportViewer 工具栏控件 [英] Programmatically trigger ReportViewer Toolbar controls
问题描述
有谁知道如何触发 ReportViewer(VS2005) 工具栏中的控件?我对创建两个按钮特别感兴趣,单击它们可以在显示的报告中前进和后退.我知道默认工具栏给了我这个功能,但是前进和后退按钮的大小对于触摸屏来说太小了.这就是为什么我考虑添加两个自定义按钮,它们可以触发工具栏的前进和后退按钮调用的相同事件.谢谢.
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.
推荐答案
这是在 VB.NET 中如何编辑 ReportViewer 组件的工具栏的示例,例如向下拉项或任何您喜欢的内容添加图像:
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
这篇关于以编程方式触发 ReportViewer 工具栏控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!