PrinterSettings.InstalledPrinters Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan nama semua pencetak yang terinstal pada komputer.
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
Nilai Properti
yang PrinterSettings.StringCollection mewakili nama semua pencetak yang terinstal pada komputer.
Pengecualian
Pencetak yang tersedia tidak dapat dijumlahkan.
Contoh
Contoh kode berikut mengisi comboInstalledPrinters
kotak kombo dengan printer yang diinstal dan juga mengatur printer untuk dicetak, menggunakan PrinterName properti , ketika pilihan berubah. PopulateInstalledPrintersCombo
Rutinitas dipanggil ketika formulir sedang diinisialisasi. Contohnya mengharuskan PrintDocument variabel bernama printDoc
ada dan bahwa kotak kombo tertentu ada.
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
Keterangan
Anda dapat menggunakan kumpulan nama printer yang terinstal untuk menyediakan pilihan pencetak yang ingin dicetak kepada pengguna.