Click here to Skip to main content
15,920,632 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I want to show the name of the printer when I use the below code. I am not getting the result. The code runs without any error but it did not show the desired result. Please help.
And also tell me how to design this form.

C#
public static StringCollection GetPrintersCollection()
{
        StringCollection printerNameCollection = new StringCollection();
        string searchQuery = "SELECT * FROM Win32_Printer";
        ManagementObjectSearcher searchPrinters =
              new ManagementObjectSearcher(searchQuery);
        ManagementObjectCollection printerCollection = searchPrinters.Get();
        foreach (ManagementObject printer in printerCollection)
        {
          MessageBox.Show(""+  printerNameCollection.Add(printer.Properties["Name"].Value.ToString()));
        }
        return printerNameCollection;
} 


Thanks!
Posted
Updated 7-Jan-11 0:18am
v2
Comments
Thomas Krojer 7-Jan-11 9:36am    
seems you never add something to the string collection ...

1 solution

You can obtain all printer names with this code:

using System.Drawing.Printing;

private void showprinters ()
{
     foreach (String printer in PrinterSettings.InstalledPrinters)
     {
         //printer.ToString()
         //You can use the printer name for everything you need.
     }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900