Csharp/CSharp Tutorial/Development/Printer

Материал из .Net Framework эксперт
Версия от 12:14, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Display all installed printer name

using System;
using System.Drawing.Printing;
class MainClass
{
    static void Main(string[] args)
    {
        foreach (string printerName in PrinterSettings.InstalledPrinters)
        {
            Console.WriteLine("Printer: {0}", printerName);
        }
    }
}

Printer settings: Display the list of valid paper sizes

using System;
using System.Drawing.Printing;
class MainClass
{
    static void Main(string[] args)
    {
        foreach (string printerName in PrinterSettings.InstalledPrinters)
        {
            Console.WriteLine("Printer: {0}", printerName);
            
            PrinterSettings printer = new PrinterSettings();
            printer.PrinterName = printerName;
            if (printer.IsValid)
            {
                Console.WriteLine("Supported Paper Sizes:");
                foreach (PaperSize size in printer.PaperSizes)
                {
                    if (Enum.IsDefined(size.Kind.GetType(), size.Kind))
                    {
                        Console.WriteLine("  {0}", size);
                    }
                }
            }
        }
    }
}

Printer settings: Display the list of valid resolutions

using System;
using System.Drawing.Printing;
class MainClass
{
    static void Main(string[] args)
    {
        foreach (string printerName in PrinterSettings.InstalledPrinters)
        {
            Console.WriteLine("Printer: {0}", printerName);
            
            PrinterSettings printer = new PrinterSettings();
            printer.PrinterName = printerName;
            if (printer.IsValid)
            {
                Console.WriteLine("Supported Resolutions:");
                foreach (PrinterResolution resolution in printer.PrinterResolutions)
                {
                    Console.WriteLine("  {0}", resolution);
                }
            }
        }
    }
}