Blog

Enlist Printer(s) on the System

Posted by Mayur Dighe Blogs | Visual C# Sep 02, 2012
The Blog demonstrate a method to enlist the printer installed on the system.
Download Files: EnlistPrinter.zip

Description

About Classes used

 #1: An object of PrintDocument class, allow for setting the properties that describe how to print, and call the Print method to start the printing process.

 
#2:  PrinterSettings class, Specifies information about how a document is printed, including the printer that prints it, when printing from a Windows Forms application.

Namespace Required - System.Drawing.Printing

Controls used:

1.    ListView Control (lvPrinters)

2.    Button Control (btnGetPrinter & btnExit)

Here I implemented the Code for enlisting the printer(s) installed on the system.          

The Code: (do necessary changes)

1. Variables Declaration.

                        Boolean value = true;
                        String Default = "";

 

Listing 1

2. Search for Default Printer.

                   // Determine Default Printer Exist or Not
                   if ((new PrintDocument()).PrinterSettings.IsDefaultPrinter == value)
            {
            // if Exist Fetch the Printer's Name
                  ListViewItem item = new ListViewItem(Default =
                                    (newPrintDocument()).PrinterSettings.PrinterName);
                  item.SubItems.Add(value.ToString());              
 
                  // Add the Default Printer's Name to ListView
                  lvPrinters.Items.Add(item);                
                 
            value = false// Reset Boolean Value to False
            }

Listing 2

3. Search for Other Printer(s)

                   
//Fetch All Installed Printer's Name
                   foreach (object var in PrinterSettings.InstalledPrinters)
            {
                  // Compare Installed Printer(s) Name with Default Printer
                  if (Default != var.ToString())
                  {
                        ListViewItem item = new ListViewItem(var.ToString());
                        item.SubItems.Add(value.ToString());

                        // Add Remaining Printer's Name to ListView
                        lvPrinters.Items.Add(item);
                  }
            }

Listing 3

4. Now execute the Application and see the result (Figure 1).

Intended Result:

New Picture (4).png
 

Figure 1

Summary:

In this piece of writing, using C# environment, we have seen how to retrieve printer(s) name installed on the system.

comments
COMMENT USING
PREMIUM SPONSORS
Infragistics is experts in technology and design, and passionate about helping you build highly performant and stylish applications that solve problems, deliver inspiration, and maximize results.
Nevron Chart
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
HTML 5 + JQUERY CONTROLS