VS2005 WinForm中的PrintPreviewDialog控件预览时如何导出其它格式的文件?工具箱自带的这个控件没有导出功能哦,只能直接打印,现在我要求这个控件要像CrystalReportViewer一样能够导出其它Excel,PDF,Word等其它格式的文件,如何实现?如果用派生类的话,这个类该如何写?
解决方案 »
- 求一段代码,实现100万个6位随机数里面出现次数最低的代码
- 打造效率最低的正则表达式
- visual C#中DataGridView中碰到的问题
- BS结构,菜鸟级问题
- .net中的子窗体和父窗体如何操作
- 哪位老大能把以下代码翻译成C#的代码,谢谢了
- .NET插入acces问题!高手救命啊!
- sql时间查询,时间包含问题
- 请教:从form1打开form2,form1隐藏(hide),然后如何重新打开form1?
- SOCKET 多线程接收数据插入数据库方法是否可行?
- 菜鸟问题:从网络读取数据失败,原因:请求因 HTTP 状态 403 失败:Access Denied
- 关于三层体系结构详解!·!!~~高手进来帮帮忙!~~
本来 就不提供导出功能 ,如果你要预览的时候,导出EXCEL ,
只有模拟一个页面,然后读取页面的内容,然后导出到EXCEL
获取工具栏
然后在工具栏添加自己的按钮
在按钮事件中添加导出代码Imports System.Reflection
Imports System.Windows.Forms
Imports System.ResourcesPublic Class PrintPreviewDialogEx
Inherits System.Windows.Forms.PrintPreviewDialog Protected WithEvents pToolBar As System.Windows.Forms.ToolBar
Private nInitialImages As Integer
Private AddedButtons As ArrayList#Region " Windows Form Designer generated code " Public Sub New()
MyBase.New() 'This call is required by the Windows Form Designer.
InitializeComponent() pToolBar = Me.ParentToolbar Dim b As Button = GetCloseButton()
b.Text = "关闭"
Me.Text = "打印预览"
AddHandler pToolBar.ButtonClick, AddressOf AddedButtons_Click
End Sub 'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub 'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Public WithEvents AddedButtonsImageList As System.Windows.Forms.ImageList
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(PrintPreviewDialogEx))
Me.AddedButtonsImageList = New System.Windows.Forms.ImageList(Me.components)
'
'AddedButtonsImageList
'
Me.AddedButtonsImageList.ImageSize = New System.Drawing.Size(16, 16)
Me.AddedButtonsImageList.TransparentColor = System.Drawing.Color.Transparent
'
'PrintPreviewDialogEx
'
Me.ClientSize = New System.Drawing.Size(864, 543)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "PrintPreviewDialogEx" End Sub#End Region Public Event AddedButtonsClick As System.Windows.Forms.ToolBarButtonClickEventHandler Private Sub AddedButtons_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs)
Dim i As Integer
For i = 0 To AddedButtons.Count - 1
If e.Button Is AddedButtons(i) Then
RaiseEvent AddedButtonsClick(Me, e)
Return
End If
Next
End Sub Public Sub AddToolBarButtons(ByVal Buttons() As System.Windows.Forms.ToolBarButton)
Dim imgList As ImageList = pToolBar.ImageList
Dim i As Integer
nInitialImages = imgList.Images.Count
AddedButtons = New ArrayList
For i = 0 To AddedButtonsImageList.Images.Count - 1
imgList.Images.Add(AddedButtonsImageList.Images.Item(i))
Next Dim initw As Integer = 0
For i = 0 To Buttons.GetLength(0) - 1
AddedButtons.Add(Buttons(i))
If Buttons(i).ImageIndex >= 0 Then
Buttons(i).ImageIndex += nInitialImages
End If
pToolBar.Buttons.Add(Buttons(i))
initw += pToolBar.Buttons(pToolBar.Buttons.Count - 1).Rectangle.Width
Next
Dim s As System.Drawing.Size = Me.MinimumSize
s.Width += initw
Me.MinimumSize = s
Dim b As Button = GetCloseButton()
b.Left += initw
End Sub Private Function GetCloseButton() As Button
Dim fi As FieldInfo = GetType(System.Windows.Forms.PrintPreviewDialog).GetField("closeButton", BindingFlags.Public Or BindingFlags.NonPublic Or BindingFlags.Instance)
Return CType(fi.GetValue(Me), System.Windows.Forms.Button)
End Function Public ReadOnly Property ParentToolbar() As System.Windows.Forms.ToolBar
Get
Dim fi As FieldInfo = GetType(System.Windows.Forms.PrintPreviewDialog).GetField("toolBar1", BindingFlags.Public Or BindingFlags.NonPublic Or BindingFlags.Instance)
Return CType(fi.GetValue(Me), System.Windows.Forms.ToolBar)
End Get
End PropertyEnd Class