Printer settings: Display the list of valid paper sizes

This tutorial will teach you on how to get and display the list of valid paper sizes of the printer. I already have this tutorial on how to display the list of printers installed in the computer. Now, let's start this tutorial! 1. Let's start with creating a Windows Form Application in C# for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application and name your project as Printer Settings. 2. Next, add a Button named button1 to get all the valid paper sizes of the printer, and listbox named listBox1 to display there the paper sizes. You must design your interface like this: design 3. In your button1 to display all the list of valid paper sizes to be printed, put this code below.
  1.  private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             // get all the installed printers
  4.             foreach (string printerName in PrinterSettings.InstalledPrinters)
  5.             {
  6.                 //call the printer settings
  7.                 PrinterSettings printer = new PrinterSettings();
  8.                 printer.PrinterName = printerName; //get the settings of a particular printer
  9.  
  10.  
  11.                 // if there is a printer
  12.                 if (printer.IsValid)
  13.                 {
  14.                     //get all the valid paper sizes for printer
  15.                     foreach (PaperSize size in printer.PaperSizes)
  16.                     {
  17.                         // get the size to the printer
  18.                         if (Enum.IsDefined(size.Kind.GetType(), size.Kind))
  19.                         {
  20.                             // added the paper sizes of the printer to the listbox
  21.                            listBox1.Items.Add( size);
  22.                         }
  23.                     }
  24.                 }
  25.             }
  26.         }
We have declared a foreach loop statment to get all the the installed printers. Inside the loop, we declare a printer variable to call the printer settings. And the printer variable holds the printerName to get the settings of a particular printer. Then, we have created an If statement for the validation of printers. Inside of it is the creation again of a foreach loop that gets the paper sizes of the printer and will be added and diplayed in the listBox. Output: output For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer If you have some queries, feel free to contact the number or e-mail below. Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Add new comment