Title | Select a printer resolution such as Draft or High in Visual Basic .NET |
Description | This example shows how to select a printer resolution such as Draft or High in Visual Basic .NET. |
Keywords | printing, printers, resolution, printer resolution, draft, set printer resolution, Visual Basic .NET, VB.NET |
Categories | Graphics, VB.NET |
|
|
When you set a PrintDocument's printer, its DefaultPageSettings.PrinterSettings.PrinterResolutions collection contains PrinterResolution objects representing the printer's available resolutions. For example, you can select one of these to print at draft resolution and save some toner.
When it starts, this program uses the following code to list the available printers in the cboPrinter 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 simply loops through the System.Drawing.Printing.PrinterSettings.InstalledPrinters collection adding the names of the printers to the ComboBox.
When the user selects a printer, the following code displays that printer's resolutions in the cboResolution ComboBox.
|
|
' Display this printer's available resolutions.
Private Sub cboPrinter_SelectedIndexChanged(ByVal sender As _
System.Object, ByVal e As System.EventArgs) Handles _
cboPrinter.SelectedIndexChanged
' Select the printer.
pdocSmiley.PrinterSettings.PrinterName = cboPrinter.Text
' Display the available resolutions.
cboResolution.Items.Clear()
For Each resolution As PrinterResolution In _
pdocSmiley.DefaultPageSettings.PrinterSettings.PrinterResolutions
cboResolution.Items.Add(resolution.ToString())
Next resolution
' Disable the Print button until the user picks a
' resolution.
btnPrint.Enabled = (cboResolution.SelectedIndex > -1)
End Sub
|
|
The code first sets the PrintDocument's printer to the one selected by the user. It then loops through the document's printer resolutions adding them to the ComboBox.
Finally when the user clicks the Print button, the following code prints on the selected printer at the selected resolution.
|
|
' 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 resolution to value selected in the corresponding ComboBox. It then calls the document's Print method to send the printout to the printer.
|
|
|
|
|
|
|