判断打印机是否存在?
本地默认打印机可能是装在本地的打印机,也可能是远程打印机映射到本地的来的。
只要判断是否存在有默认打印机 ?
小弟迷茫中,请大侠赐教!!
------解决方案--------------------http://www.codeproject.com/cs/system/GetHardwareInformation.asp
获得计算机大部分的硬件信息
------解决方案--------------------其中有一个Win32_Printer就是你要的信息了
------解决方案--------------------http://www.mltang.com/article/a228282f-411b-4009-ad46-1aca06f9f1e2.html
------解决方案--------------------Visual Basic 复制代码
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
C# 复制代码
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;
}
}
——MSDN上的