有2种方法可以实现:
1) 使用PrintDocument 和PrintDialog 组件
在.NET Framework 中提供强大的打印功能。
PrintDocument 组件:
在.NET Framework中,打印文档要使用PrintDocument组件,它包含了所有要打印的信息。并且处理打印相关的事件。
PrintDialog 组件:
要打印一个文档,需要设置PrintDialog 的文档属性,并且使用PrintDocument 的打印方法。如果要发送东西给打印机,你就必须处理PrintDocument_printPage 事件去传递东西。
Private Sub buttonPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim printDialog1 As PrintDialog = New PrintDialog
printDialog1.Document = printDocument1
Dim result As DialogResult = printDialog1.ShowDialog
If (result = DialogResult.OK) Then
printDocument1.Print()
End If
End Sub
代码示例:
http://social.msdn.microsoft.com/Forums/en-US/vbpowerpacks/thread/2ad34554-e989-4ffa-8e1f-ccea1f00c99d
相关资料:
Article: Printing feature in .NET Framework
http://www.startvbdotnet.com/controls/printdialog.aspx
Windows Forms Printing
http://www.syncfusion.com/faq/windowsforms/faq_c55c.aspx#q491q
How to print the content of RichTextBox using Visual Basic .NET?
http://support.microsoft.com/kb/811401
2) 使用 VB Power Packs 打印组件
PrintForm 组件的设计是能够简单方面的打印窗体。这使得您完全可以按照自己的需求设计窗体,并且允许您将窗体作为快速报告形式打印。
MS VB Power Paceks 3.0 下载地址:
http://msdn.microsoft.com/en-us/vbasic/bb735936.aspx
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.Scrollable)
End Sub
更详细的代码:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim psi As New ProcessStartInfo
psi.UseShellExecute = True
psi.Verb = "print"
psi.WindowStyle = ProcessWindowStyle.Hidden
'psi.Arguments = PrintDialog1.PrinterSettings.PrinterName.ToString()
psi.FileName = "C:\MyFile.doc”
Process.Start(psi)
End Sub
End Class
如果您对我们的论坛在线支持服务有任何的意见或建议,请通过
邮件告诉我们。
立刻免费下载
MSDN 论坛好帮手