PrinterSettings.InstalledPrinters 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取安装在计算机上所有打印机的名称。
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
注解
可以使用已安装打印机名称的集合为用户提供打印到的打印机选项。