• C#获取系统默认打印机和已安装的打印机列表


     1 using System;   
     2 using System.Collections.Generic;   
     3 using System.Windows.Forms;   
     4 using System.Drawing.Printing;   
     5 namespace FindPrinterDemo   
     6 {   
     7     public partial class Demo : Form   
     8     {   
     9         public Demo()   
    10         {   
    11             this.Text= "本地打印机列表";   
    12             ListBox fListBox = new ListBox();   
    13             fListBox.Dock = DockStyle.Fill;   
    14             foreach (String fPrinterName in LocalPrinter.GetLocalPrinters())   
    15                 fListBox.Items.Add(fPrinterName);   
    16             this.Controls.Add(fListBox);   
    17         }   
    18     } 
    19   
    20     /// </summary>    
    21     public class LocalPrinter   
    22     {   
    23         private static PrintDocument fPrintDocument = new PrintDocument();   
    24         /// <summary>    
    25         /// 获取本机默认打印机名称    
    26         /// </summary>    
    27         public static String DefaultPrinter   
    28         {   
    29             get { return fPrintDocument.PrinterSettings.PrinterName; }   
    30         }   
    31         /// <summary>    
    32         /// 获取本机的打印机列表。列表中的第一项就是默认打印机。    
    33         /// </summary>    
    34         public static List<String> GetLocalPrinters()   
    35         {   
    36             List<String> fPrinters = new List<string>();   
    37             fPrinters.Add(DefaultPrinter); // 默认打印机始终出现在列表的第一项    
    38             foreach (String fPrinterName in PrinterSettings.InstalledPrinters)   
    39             {   
    40                 if (!fPrinters.Contains(fPrinterName))   
    41                     fPrinters.Add(fPrinterName);   
    42             }   
    43             return fPrinters;   
    44         }   
    45     }   
    46 }   
  • 相关阅读:
    synchronize模块
    ansible 的user模块
    copy src remote_src false表示本地,true在远程
    import_tasks: tasks/sometasks.yml
    ansible 变量传递到include
    ansible unarchive模块
    防火墙在setup进入不了
    telegram汉化和代理
    Ubuntu 18.04 一键安装深度截图工具 Deepin Screenshot
    8086汇编语言程序设计——子程序与模块化
  • 原文地址:https://www.cnblogs.com/mikechang/p/2380452.html
Copyright © 2020-2023  润新知