I would like set the printer device through VB. How I can do that.
Printable View
I would like set the printer device through VB. How I can do that.
Printer.Devicename = "HP Laserjet"
:)
I want to show the printer dialog and then set the name in the textbox. Actually I don't want to print. I just to set only.
I able to populate the printer devices into combo box. The problem is how I can set the printer devices as default?
Code:Private Sub Form_Load()
'Add all the available printers to the combo box
For i% = 0 To Printers.Count - 1
Combo1.AddItem Printers(i%).DeviceName
Next i%
'Display the default printer
For i% = 0 To Combo1.ListCount - 1
If Combo1.List(i%) = Printer.DeviceName Then
Combo1.ListIndex = i%
Exit For
End If
Next i%
End Sub
in the combo click event
note this does not change the windows default printer, it sets the printer your program will usevb Code:
dim p as printer for each p in printers if p.devicename = combo1.text then set printer = p: exit for next
Why it does't change the printer default in control panel?
because that is not what it does, if you want to change the windows default printer, you can use the SetDefaultPrinter api, do a search for that, in general you should change the default printer back, when you finish with it
Nevermind, I will see it later. Let try your sample first. Let say I have chose the printer from combo list and want to use this printer for printing. How to print on paper using the selected printer?
I want to see how it works to print it on paper by the selected printer of choice and which printer name it will used to print the paper.
vb Code:
printer.print "this is a test" ' print something printer.enddoc ' finish
set the printer you want to print to first