We can get the list of Printer(s) installed on a particular machine by using the following method.
|
First of all we have to use the “System.Drawing.Printing” namespace. PrintDocument and PrinterSettings classes are present inside this namespace. Using these classes we can easily get the list of Printer(s).
|
private bool GetPrinterList() { bool retVal = false; PrintDocument prtdoc = new PrintDocument(); //prt.PrinterSettings.PrinterName returns the name of the Default Printer string strDefaultPrinter = prtdoc.PrinterSettings.PrinterName; //this will loop through all the Installed printers and add the Printer Names to a ComboBox. foreach (String strPrinter in PrinterSettings.InstalledPrinters) { cmbPrinter.Properties.Items.Add(strPrinter); //This will set the ComboBox Index where the Default Printer Name matches with the current Printer Name returned by for loop if (strPrinter.CompareTo(strDefaultPrinter) == 0) { cmbPrinter.SelectedIndex = cmbPrinter.Properties.Items.IndexOf(strPrinter); retVal = true; } } return retVal; }