PrinterSettings.InstalledPrinters 属性
获取安装在计算机上所有打印机的名称。
**命名空间:**System.Drawing.Printing
**程序集:**System.Drawing(在 system.drawing.dll 中)
语法
声明
Public Shared ReadOnly Property InstalledPrinters As StringCollection
用法
Dim value As StringCollection
value = PrinterSettings.InstalledPrinters
public static StringCollection InstalledPrinters { get; }
public:
static property StringCollection^ InstalledPrinters {
StringCollection^ get ();
}
/** @property */
public static StringCollection get_InstalledPrinters ()
public static function get InstalledPrinters () : StringCollection
属性值
PrinterSettings.StringCollection,它表示安装在计算机上所有打印机的名称。
异常
异常类型 | 条件 |
---|---|
未能枚举可用的打印机。 |
备注
可以使用已安装的打印机名称的集合向用户提供要打印到的打印机选择。
示例
下面的代码示例在所选内容发生变化时,使用 PrinterName 属性将已安装的打印机填充到 comboInstalledPrinters
组合框中并设置要进行打印的打印机。在窗体初始化过程中调用 PopulateInstalledPrintersCombo
例程。该示例要求名为 printDoc
的 PrintDocument 变量和特定的组合框都已存在。
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
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:
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.get_InstalledPrinters().
get_Count(); i++) {
pkInstalledPrinters = PrinterSettings.get_InstalledPrinters().
get_Item(i);
comboInstalledPrinters.get_Items().Add(pkInstalledPrinters);
}
} //PopulateInstalledPrintersCombo
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.get_SelectedIndex() != -1) {
// The combo box's Text property returns the selected item's
// text, which is the printer name.
printDoc.get_PrinterSettings().
set_PrinterName(comboInstalledPrinters.get_Text());
}
} //comboInstalledPrinters_SelectionChanged
.NET Framework 安全性
- PrintingPermission 用于打印和访问网络上的所有打印机。关联的枚举:PrintingPermissionLevel.AllPrinting
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
PrinterSettings 类
PrinterSettings 成员
System.Drawing.Printing 命名空间
PrinterName