PrinterSettings.InstalledPrinters Propriedade
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Obtém os nomes de todas as impressoras instaladas no computador.
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
Um PrinterSettings.StringCollection que representa os nomes de todas as impressoras instaladas no computador.
Não foi possível enumerar as impressoras disponíveis.
O exemplo de código a seguir preenche a comboInstalledPrinters
caixa de combinação com as impressoras instaladas e também define a impressora para imprimir, usando a PrinterName propriedade , quando a seleção é alterada. A PopulateInstalledPrintersCombo
rotina é chamada quando o formulário está sendo inicializado. O exemplo requer que exista uma PrintDocument variável chamada printDoc
e que a caixa de combinação específica exista.
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
Você pode usar a coleção de nomes de impressora instalados para fornecer ao usuário uma opção de impressoras para imprimir.
Produto | Versões |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
Comentários do .NET
O .NET é um projeto código aberto. Selecione um link para fornecer comentários: