Printing with vb.net

拥有回忆 提交于 2019-12-23 14:24:24

问题


Is there any simple way to print to a printer with VB.NET?

Specifically, with the console. It seems that stuff that works with forms applications dont work with the console.


回答1:


Lifted from http://visualbasic.about.com/od/usingvbnet/a/printvb2005.htm

Public Class myPrinter
   Friend TextToBePrinted As String
   Public Sub prt(ByVal text As String)
      TextToBePrinted = text
      Dim prn As New Printing.PrintDocument
      Using (prn)
         prn.PrinterSettings.PrinterName _
            = "PrinterName"
         AddHandler prn.PrintPage, _
            AddressOf Me.PrintPageHandler
         prn.Print()
         RemoveHandler prn.PrintPage, _
            AddressOf Me.PrintPageHandler
      End Using
   End Sub
   Private Sub PrintPageHandler(ByVal sender As Object, _
      ByVal args As Printing.PrintPageEventArgs)
      Dim myFont As New Font("Microsoft San Serif", 10)
         args.Graphics.DrawString(TextToBePrinted, _
            New Font(myFont, FontStyle.Regular), _
            Brushes.Black, 50, 50)
   End Sub
End Class

Called as follows:

Dim printer As New myPrinter
printer.prt "Hello World"



回答2:


Look at the PrintDocument class.

Defines a reusable object that sends output to a printer, when printing from a Windows Forms application.




回答3:


Okay this post is old but from my understanding of the question, you wanted to print a string to the console, in other words :

System.Console.Write("My magnificent string !")



回答4:


Easiest way I can think of is using a Printing Engine such as CrystalReports.



来源:https://stackoverflow.com/questions/4168117/printing-with-vb-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!