用心做好每一件事情!

C# 获取打印机列表以及串口

C# 获取打印机列表以及默认打印机、串口列表。

 

/// <summary>
        /// 获取本地已安装的打印机
        /// </summary>
        /// <returns></returns>
        public string GetPrinter()
        {
            string strList = "";
            System.Drawing.Printing.PrinterSettings.StringCollection PrinterList = System.Drawing.Printing.PrinterSettings.InstalledPrinters;
            foreach (var item in PrinterList)
            {
                strList += item + ",";
            }
            return strList;
        }


        /// <summary>
        /// 获取默认打印机
        /// </summary>
        /// <returns></returns>
        public string GetDefault() 
        {
            System.Drawing.Printing.PrintDocument p = new System.Drawing.Printing.PrintDocument();
            return p.DefaultPageSettings.PrinterSettings.PrinterName;
        }

        /// <summary>
        /// 获取可用的端口
        /// </summary>
        /// <returns></returns> 
        public static List<string> GetComList()
        {
            List<string> ComList = new List<string>();
            Microsoft.VisualBasic.Devices.Computer pc = new Microsoft.VisualBasic.Devices.Computer();
            foreach (string s in pc.Ports.SerialPortNames)
            {
                ComList.Add(s);
            }
            return ComList;
        }
posted @ 2014-07-18 17:56  无 影  阅读(2403)  评论(0编辑  收藏  举报
作者: Allen【QQ:96966 1314】 网名:无影 出处: http://www.cnblogs.com/allen0118/ 声明: 本文版权归作者和博客园共有!转载时必须保留此段声明,且在文章页面明显位置给出原文连接。