PrinterSettings.InstalledPrinters Proprietà

Definizione

Ottiene i nomi di tutte le stampanti installate nel computer.Gets the names of all printers installed on the computer.

public:
 static property System::Drawing::Printing::PrinterSettings::StringCollection ^ InstalledPrinters { System::Drawing::Printing::PrinterSettings::StringCollection ^ get(); };
public static System.Drawing.Printing.PrinterSettings.StringCollection InstalledPrinters { get; }
member this.InstalledPrinters : System.Drawing.Printing.PrinterSettings.StringCollection
Public Shared ReadOnly Property InstalledPrinters As PrinterSettings.StringCollection

Valore della proprietà

Oggetto PrinterSettings.StringCollection che rappresenta i nomi di tutte le stampanti installate nel computer.A PrinterSettings.StringCollection that represents the names of all printers installed on the computer.

Eccezioni

Impossibile enumerare le stampanti disponibili.The available printers could not be enumerated.

Esempi

Nell'esempio di codice seguente viene popolata la comboInstalledPrinters casella combinata con le stampanti installate e viene impostata la stampante per la stampa, utilizzando la PrinterName proprietà, quando la selezione viene modificata.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. La PopulateInstalledPrintersCombo routine viene chiamata quando il modulo viene inizializzato.The PopulateInstalledPrintersCombo routine is called when the form is being initialized. Per l'esempio è necessario PrintDocument che esista printDoc una variabile denominata e che la casella combinata specifica esista.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 );
      }
   }

   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.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 Sub PopulateInstalledPrintersCombo()
    ' Add list of installed printers found to the combo box.
    ' The pkInstalledPrinters string will be used to provide the display string.
    Dim i as Integer
    Dim pkInstalledPrinters As String

    For i = 0 to PrinterSettings.InstalledPrinters.Count - 1
        pkInstalledPrinters = PrinterSettings.InstalledPrinters.Item(i)
        comboInstalledPrinters.Items.Add(pkInstalledPrinters)
    Next
End Sub

Private Sub comboInstalledPrinters_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles comboInstalledPrinters.SelectedIndexChanged
    ' Set the printer to a printer in the combo box when the selection changes.

    If comboInstalledPrinters.SelectedIndex <> -1 Then
        ' The combo box's Text property returns the selected item's text, which is the printer name.
        printDoc.PrinterSettings.PrinterName = comboInstalledPrinters.Text
    End If


End Sub

Commenti

È possibile utilizzare la raccolta di nomi di stampanti installate per fornire all'utente una scelta di stampanti da stampare.You can use the collection of installed printer names to provide the user a choice of printers to print to.

Sicurezza

PrintingPermission
per la stampa e l'accesso a tutte le stampanti sulla rete.for printing and access to all printers on the network. Enumerazione associata:AllPrintingAssociated enumeration: AllPrinting

Si applica a

Vedi anche