This documentation is archived and is not being maintained.

PrinterSettings.InstalledPrinters Property

Gets the names of all printers installed on the computer.

Namespace: System.Drawing.Printing
Assembly: System.Drawing (in system.drawing.dll)

public static StringCollection InstalledPrinters { get; }
/** @property */
public static StringCollection get_InstalledPrinters ()

public static function get InstalledPrinters () : StringCollection

Not applicable.

Property Value

A PrinterSettings.StringCollection that represents the names of all printers installed on the computer.

Exception typeCondition

Win32Exception

The available printers could not be enumerated.

You can use the collection of installed printer names to provide the user a choice of printers to print to.

The following code example populates the comboInstalledPrinters combo box with the installed printers and also sets the printer to print, using the PrinterName property, when the selection changes. The PopulateInstalledPrintersCombo routine is called when the form is being initialized. The example requires that a PrintDocument variable named printDoc exists and that the specific combo box exists.

private void PopulateInstalledPrintersCombo()
{
    // Add list of installed printers found to the combo box.
    // The pkInstalledPrinters string will be used to provide the display string.
    String pkInstalledPrinters;
    for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++){
        pkInstalledPrinters = PrinterSettings.InstalledPrinters[i];
        comboInstalledPrinters.Items.Add(pkInstalledPrinters);
    }
}

private void comboInstalledPrinters_SelectionChanged(object sender, System.EventArgs e)
{

    // Set the printer to a printer in the combo box when the selection changes.

    if (comboInstalledPrinters.SelectedIndex != -1) 
    {
        // The combo box's Text property returns the selected item's text, which is the printer name.
        printDoc.PrinterSettings.PrinterName= comboInstalledPrinters.Text;
    }

}

private void PopulateInstalledPrintersCombo()
{
    // Add list of installed printers found to the combo box.
    // The pkInstalledPrinters string will be used to provide the 
    // display string.
    String pkInstalledPrinters;
    for (int i = 0; i < PrinterSettings.get_InstalledPrinters().
        get_Count(); i++) {
        pkInstalledPrinters = PrinterSettings.get_InstalledPrinters().
            get_Item(i);
        comboInstalledPrinters.get_Items().Add(pkInstalledPrinters);
    }
} //PopulateInstalledPrintersCombo

private void comboInstalledPrinters_SelectionChanged(Object sender, 
    System.EventArgs e)
{
    // Set the printer to a printer in the combo box when the 
    // selection changes.
    if (comboInstalledPrinters.get_SelectedIndex() != -1) {
        // The combo box's Text property returns the selected item's
        // text, which is the printer name.
        printDoc.get_PrinterSettings().
            set_PrinterName(comboInstalledPrinters.get_Text());
    }
} //comboInstalledPrinters_SelectionChanged

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Show: