Using IsDefaultPrinter

  • Thread starter Thread starter Phil Galey
  • Start date Start date
P

Phil Galey

The documentation for IsDefaultPrinter states that it works only if the PrinterName property is null. So if you're looping through the list of installed printers, how do you use IsDefaultPrinter to determine whether each one is the default printer? In the following code, I'm filling a checked listbox with printer names and try to check only the one that is the default printer. The IsDefaultPrinter property returns true for all of them because I'm not specifying the PrinterName. The documentation says that if I do specify PrinterName, IsDefaultPrinter will
always return False.
-----------------------------------------------------------------------------------------
Dim ptr As String, ptrs As String
Dim pd As New PrintDialog()

pd.Document = New Printing.PrintDocument()
For Each ptr In pd.PrinterSettings.InstalledPrinters
'pd.PrinterSettings.PrinterName = ptr <== Forbidden
clbPrinters.Items.Add(ptr, pd.PrinterSettings.IsDefaultPrinter)
Next
 
Hi,

Answering to your question that how to determine the printer as a default
printer.

The following code in vb.net can help you out.


Dim prntSettigns as New System.Drawing.Printing.PrinterSettings
Dim strDefaultPrinter as String
strDefaultPrinter = prntSettigns.PrinterName

For Filling in all the printers in the dialog box and default the list to
the default printers, you may use the following code:

Dim prntSettigns as New System.Drawing.Printing.PrinterSettings
Dim strDefaultPrinter as String
strDefaultPrinter = prntSettigns.PrinterName
Dim strPrinter as String

For Each strPrinter in System.Drawing.Printing..InstalledPrinters
clbPrinters.Items.Add(strPrinter)
Next
clbPrinters.SelectedIndex = clbPrinters.Items.IndexOf(strDefaultPrinter)

Hope this solves your question.

Thanks and Regards,

Piyush Thakuria
 
Back
Top