Printing with vb.net

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.

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"

VB.Net - PrintDialog Control, VB.Net - PrintDialog Control - The PrintDialog control lets the user to print documents by selecting a printer and choosing which sections of the document to print� It is true that printing in VB6 was much easier than what we are offered in VB.Net, but in VB.Net we have much more control over the entire print process, even setting up the document, and formatting the text. In VB6 it was a simple call to Printer.Print and voila your document would print.

Look at the PrintDocument class.

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

Printing - Programming Visual Basic .NET [Book], Printing Most Visual Basic .NET programs will never need to use the .NET Framework's native printing capabilities. Reporting tools such as Crystal Reports, � Like a lot of things, printing forms should be easier than it sometimes is. Visual Basic .NET as well as WinForms have gone through a lot of changes in recent years, and those changes have meant that means of printing have had to be learned anew.

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 !")

VB Printing Samples: How to Print a Form in VB.net, There is really no need to use the Power Pack it is all built into VB now. Program Output Print Preview. 'prints form fit to page and centered with preview. Public� VB.Net - PrintDialog Control - The PrintDialog control lets the user to print documents by selecting a printer and choosing which sections of the document to print from a Windows Forms applic Home Jobs

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

An Absolute Beginner's Guide to Printing in .NET, The printing subsystem can be particularly daunting the first time it is encountered. It is unfamiliar to NET. Printing in .NET follows the overview of the print system quite closely. Microsoft MVP (Visual Basic) 2006, 2007� Its Monday, and it now works. an Import Printing.Drawing statement is needed(as well as referencing system.drawing). A small help is to use rinting.PrinterSettings.InstalledPrinters.Item(0) to find the printer you want instead of typing in something in "PrinterName" .

HowTo: Print and display print previews in VB .NET, NET. It shows how to use the PrintDocument object to print, how to print with the PrintDialog control, and how to display a print preview with the PrintPreviewDialog� VB Printing Tips 1. How To Print a Form Image. This example shows how to capture a Windows Form image and print it. The image is resized and centered to fit the Print Margins. The example shows the Print Preview dialog. To print click the Print button on the dialog. Many programmers attempt this with the old Power Pack Printform control

Using the PrintDocument component in VB.NET applications , The text found in the TextBox (usually TextBox1, assuming that you didn't change it), will print to the default printer. When the button is clicked, two� VB.NET forum discussion. ICSharp ZIP library C# to VB.NET Port by Garry Wang (6 replies) Printing with formatting in VB.NET by jclebon (7 replies) IP2Location Geolocation .NET Component in VB.NET by dunking (5 replies) Watching Folder Activity in VB.NET by emmaddai (17 replies) print a document file without using print dialog control in Vb.net

Print preview and print in vb.net applications - MSDN, PrinterSettings 'set the page setup dialog to the print document See these threads which about printing a form in vb.net, maybe it will be� MSDN Visual Basic Community To print a document or provide a preview, the program creates a PrintDocument object. It assigns event handlers to this object's BeginPrint, QueryPageSettings, PrintPage, and EndPrint events. PrintPage is the one that generates the output and it's the only one that is required.

Comments
  • What are you trying to print? Text in a TextArea? The Window itself?
  • I want to print a string of text a user enters in the console.
  • Did you actually try that? "Printing" is not defined for me.
  • That is because I am using a console application instead of a forms application. Thanks to Oded parts of the problems went away when I referenced system.drawing. And then changed "Printing." to "Drawing.Printing."
  • Its Monday, and it now works. an Import Printing.Drawing statement is needed(as well as referencing system.drawing). A small help is to use rinting.PrinterSettings.InstalledPrinters.Item(0) to find the printer you want instead of typing in something in "PrinterName".
  • @PatrickMcDonald LINK
  • Is there anything like that for a console application?
  • @Oak - Any reason why you can't use the System.Drawing.Printing namespace in your console application? Just add a reference in your project and you should be good to go.
  • Yea, my newness to vb.net. Thanks!
  • No, OP wanted to print to a printer - as evidenced by the fact they accepted an answer which does just that, 6 years before you posted!
  • In this case using another tool does not count as simple. But thanks for the idea! Ideally simple would mean Print("text")