How to Print to a Specific Printer in VB.NET


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.

  • 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 :


Related Searches


Promoted By Zergnet


Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!