I've made a program that will run on startup asking the users to select their default printer. The code shows all installed printers in a ComboBox and the submit Button will set the Printer selected in the ComboBox as the default printer for that user.
Is there a way I can only show Printers names that contain specific text?
As e.g.:
ABC
printer1ABC
network1 abc
printer2 def
network2def
So it would only show printer1ABC
and network1 abc
?
Here's the code I have so far (one ComboBox and one Button)
Imports System.Drawing.Printing
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strInstalledPrinters As String
Dim prntDoc As New PrintDocument
'check if there is installed printer
If PrinterSettings.InstalledPrinters.Count = 0 Then
MsgBox("No printer installed")
Exit Sub
End If
'display installed printer into combobox list item
For Each strInstalledPrinters In PrinterSettings.InstalledPrinters
ComboBox1.Items.Add(strInstalledPrinters)
Next strInstalledPrinters
'Display current default printer on combobox texts
ComboBox1.Text = prntDoc.PrinterSettings.PrinterName
Button1.Text = "Set Default Printer"
End Sub
End Class
Function to set a printer as default:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Shell(String.Format("rundll32 printui.dll,PrintUIEntry /y /n ""{0}""", ComboBox1.Text))
MsgBox("You have changed your default printer")
Me.Close()
End Sub
Thanks for any help