C#获取所有打印机

发布时间:2020-06-02编辑:佚名阅读(2025)

List<string> print = Cprinter.GetLocalPrinter();
    /// <summary>
    /// 获取所有打印机    
    /// </summary>
    public class Cprinter
    {        
        private static PrintDocument fPrintDocument = new PrintDocument();        
        ///<summary>
        ///获取本地默认打印机名称        
        ///</summary>
        public static string DefaultPrinter
        {            
            get 
            { 
                return fPrintDocument.PrinterSettings.PrinterName; 
            }
        }        
        /// <summary>
        ///  获取本地打印机的列表,第一项就是默认打印机        
        /// </summary>
        public static List<string> GetLocalPrinter()
        {
            List<string> fPrinters = new List<string>();
            fPrinters.Add(DefaultPrinter);  //默认打印机出现在列表的第一项
            foreach (string fPrinterName in PrinterSettings.InstalledPrinters)
            {                
                if (!fPrinters.Contains(fPrinterName))
                    fPrinters.Add(fPrinterName);
            }            
            return fPrinters;
        }
    }


    关键字: C# 获取所有打印机


鼓掌

0

正能量

0

0

呵呵

0


评论区