zoukankan      html  css  js  c++  java
  • 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 }   
  • 相关阅读:
    运行monkeyrunner脚本
    Monkey
    ubuntu下在Eclipse中配置MonkeyRunner环境
    ubuntu下Gradle离线安装
    ubuntu下反编译apk
    PuTTY 设置Serial(ubuntu)
    工作中接触的命令
    自动化功能测试(QTP)汉化12.0
    App测试工作
    vue项目在vscode中编译eslint报错没显示红色波浪线提示
  • 原文地址:https://www.cnblogs.com/mikechang/p/2380452.html
Copyright © 2011-2022 走看看