|
|
Title | Let the user select a printer and then send a printout directly to it in Visual Basic .NET |
Description | This example shows how to let the user select a printer and then send a printout directly to it in Visual Basic .NET. |
Keywords | printing, printers, send to printer, printout, select printer, pick printer, Visual Basic .NET, VB.NET |
Categories | Graphics, 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.
|
|
|
|
|
 |
|
|
|