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 }   

转载于:https://www.cnblogs.com/mikechang/archive/2012/03/05/2380452.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值