PrinterSettings.InstalledPrinters 屬性

定義

取得安裝於電腦上的所有印表機名稱。

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

屬性值

PrinterSettings.StringCollection,表示安裝於電腦上的所有印表機名稱。

例外狀況

無法列舉可用的印表機。

範例

下列程式代碼範例會將 comboInstalledPrinters 已安裝的印表機填入下拉式方塊,並在選取範圍變更時,使用 PrinterName 屬性將印表機設定為列印。 初始化 PopulateInstalledPrintersCombo 表單時會呼叫例程。 此範例會要求 PrintDocument 名為 printDoc 的變數存在,而且有特定的下拉式方塊存在。

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

備註

您可以使用已安裝印表機名稱的集合,讓使用者選擇要列印的印表機。

適用於

另請參閱