Installed Printers in 2005 beta 2
I am trying to get a list of installed printers. I added a form and a printdialog1 and the following code:
Dim iAsInteger
Dim pkInstalledPrintersAsStringDim printdocAsStringFor i = 0To PrintDialog1.InstalledPrinters.Count - 1pkInstalledPrinters = PrinterSettings.InstalledPrinters.Item(i)
comboinstalledprinters.Items.Add(pkInstalledPrinters)
NextForEach pkInstalledPrintersIn PrinterSettings.InstalledPrinterscomboinstalledprinters.Items.Add(pkInstalledPrinters)
Next1. printdialog1.installedprinters returns a message not being a member of printdialog1.
2. PrinterSettings shows as not being declared.
This code if from MSDN, probably for .net2003
[1705 byte] By [
jmorgan] at [2008-2-17]
Hi,
Try this,
Dim i As Integer
Dim pkInstalledPrinters As StringFor i = 0 to PrintDialog1.PrinterSettings.InstalledPrinters.Count - 1
pkInstalledPrinters = PrintDialog1.PrinterSettings.InstalledPrinters.Item(i)
comboinstalledprinters.Items.Add(pkInstalledPrinters)
Next
your first problem in your code is that InstalledPrinters object is not a member of printDialog1 it is really a member of PrintDialog1.PrinterSettings Object...Your second problem is that you directly referenced PrinterSettings object without first referencing the printDialog1 Object.
If you want to create a variable to hold the printersettings object:
Dim ps As System.Drawing.Printing.PrinterSettings
ps = PrintDialog1.PrinterSettings
And just replace all the PrintDialog1.PrinterSettings instances in your code with ps.
cheers,
Paul June A. Domag
Thanks
I changed the code to below
Dim ps As System.Drawing.Printing.PrinterSettings
ps = PrintDialog1.PrinterSettings
Dim i As Integer
Dim pkInstalledPrinters As String For i = 0 To ps.PrinterSettings.InstalledPrinters.Count - 1 pkInstalledPrinters = ps.InstalledPrinters.Item(i)
comboinstalledprinters.Items.Add(pkInstalledPrinters)
NextBut I get a message:
- on the ps.PrinterSettings.InstalledPrinters.count -1 line of
PrinterSettings is not a member of 'System.drawing.printing.printersetting


This works, I don't know why the ps variable doesn't work though?
Dim pkInstalledPrinters As String
For i = 0 To System.Drawing.Printing.PrinterSettings.InstalledPrinters.Count - 1 pkInstalledPrinters = System.Drawing.Printing.PrinterSettings.InstalledPrinters.Item(i)
comboinstalledprinters.Items.Add(pkInstalledPrinters)
NextHi,
Got puzzled with that for a moment. 
you should do it this way...
Dim ps As System.Drawing.Printing.PrinterSettings
ps = PrintDialog1.PrinterSettings
Dim i As Integer
Dim pkInstalledPrinters As String '' Edit Here-
''For i = 0 To ps.PrinterSettings.InstalledPrinters.Count - 1
'' Change to
For i = 0 To ps.InstalledPrinters.Count - 1
pkInstalledPrinters = ps.InstalledPrinters.Item(i)
comboinstalledprinters.Items.Add(pkInstalledPrinters)
Next
But you could always use the System.Drawing.Printing.PrinterSettings.InstalledPrinters object directly for it is static and contains the list of installed printers upon runtime...
cheers,
Paul June A. Domag