CÁC GIẢI PHÁP LẬP TRÌNH C# - Trang 318

318
Chương 8: Đồ họa, đa phương tiện, và in ấn

public class ListPrinters {

private static void Main(string[] args) {

foreach (string printerName in

PrinterSettings.InstalledPrinters) {

// Hiển thị tên máy in.

Console.WriteLine("Printer: {0}", printerName);

// Lấy các thiết lập máy in.

PrinterSettings printer = new PrinterSettings();

printer.PrinterName = printerName;

// Kiểm tra tính hợp lệ của máy in.

// (Bước này cần thiết trong trường hợp bạn đọc tên máy in

// từ một giá trị do người dùng cấp hoặc một thiết lập trong

// file registry hay configuration.)

if (printer.IsValid) {

// Hiển thị danh sách các độ phân giải hợp lệ.

Console.WriteLine("Supported Resolutions:");

foreach (PrinterResolution resolution in

printer.PrinterResolutions) {

Console.WriteLine(" {0}", resolution);

}

Console.WriteLine();

// Hiển thị danh sách các khổ giấy hợp lệ.

Console.WriteLine("Supported Paper Sizes:");

foreach (PaperSize size in printer.PaperSizes) {

if (Enum.IsDefined(size.Kind.GetType(), size.Kind)) {