The VB.NET "PrintDocument" class lets you define a document and printer, so you can send a print job to a printing device on the computer or on the network. You define the printer to which you want to print in the "PrinterSettings" property. If you do not define a printer, VB.NET prints to the default printer set up in the Windows system.
- Skill level:
Other People Are Reading
Right-click the VB.NET SLN file on your computer, click "Open With" and double-click the "Visual Studio" icon to load the VB.NET project in the work space.
Double-click the code file you want to use in "Solution Explorer." Scroll down the file to the function you want to use to print a document.
Define a "StreamReader" variable:
Dim stream As StreamReader
stream = New StreamReader("C:\file.txt")
This variable imports all text and layouts from a file to print to a printer. Replace "C:\file.txt" with any location and file you want to print.
Set up the printer using the printer name set up in the Windows system:
Dim printer As New PrintDocument()
printer.PrinterSettings.PrinterName = "HP Deskjet"
Replace the "HP Deskjet" name with the name of the printer on the computer.
Use the "Print" function to print the document by adding the following code :
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for