다음을 통해 공유


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 폼이 초기화될 때 호출됩니다. 이 예제에서는 라는 printDoc 변수가 PrintDocument 있고 특정 콤보 상자가 있어야 합니다.

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

설명

설치된 프린터 이름 컬렉션을 사용하여 사용자에게 인쇄할 프린터를 선택할 수 있습니다.

적용 대상

추가 정보