Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleLet the user select a printer and then send a printout directly to it in Visual Basic .NET
DescriptionThis example shows how to let the user select a printer and then send a printout directly to it in Visual Basic .NET.
Keywordsprinting, printers, send to printer, printout, select printer, pick printer, Visual Basic .NET, VB.NET
CategoriesGraphics, VB.NET
 

When it starts, the program uses the following code to display the available printers in a ComboBox.

 
' List the available printers.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    For Each printer As String In _
        PrinterSettings.InstalledPrinters
        cboPrinter.Items.Add(printer)
    Next printer
End Sub
 
This code loops through the System.Drawing.Printing.PrinterSettings.InstalledPrinters collection, adding each printer's name to the ComboBox.

When the user selects a printer and clicks the Print button, the following code sends the printout to the selected printer.

 
' Print.
Private Sub btnPrint_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnPrint.Click
    ' Select the printer.
    pdocSmiley.PrinterSettings.PrinterName = cboPrinter.Text

    ' Print.
    pdocSmiley.Print()
End Sub
 
This code sets the PrintDocument's printer name to the selected printer's name and then calls the PrintDocument's Print method to generate the printout.
 
 
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated