码迷,mamicode.com
首页 > Windows程序 > 详细

C# 默认打印机设置

时间:2019-07-23 17:00:05      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:code   each   str   bin   imp   set   prope   contains   vat   

技术图片

 

private void frmBarCode_Load(object sender, EventArgs e)
{

 bindCbox();

}

#region 选择打印机
[DllImport("winspool.drv")]
public static extern bool SetDefaultPrinter(String Name); //调用win api将指定名称的打印机设置为默认打印机

private static PrintDocument fPrintDocument = new PrintDocument();
//获取本机默认打印机名称
public static String DefaultPrinter()
{
return fPrintDocument.PrinterSettings.PrinterName;
}
public static List<String> GetLocalPrinters()
{
List<String> fPrinters = new List<String>();
fPrinters.Add(DefaultPrinter()); //默认打印机始终出现在列表的第一项
foreach (String fPrinterName in PrinterSettings.InstalledPrinters)
{
if (!fPrinters.Contains(fPrinterName))
{
fPrinters.Add(fPrinterName);
}
}
return fPrinters;
}

//获取当前默认打印机信息

private void bindCbox()
{
List<String> PrinterList = new List<String>();
PrinterList = GetLocalPrinters();
foreach (String strpinter in PrinterList)
{
cmbPrinter.Properties.Items.Add(strpinter);
}
if (cmbPrinter.SelectedItem == null)
{
cmbPrinter.SelectedIndex = 0;
}
else
{
cmbPrinter.SelectedIndex = 0;
}
}

private void cmbPrinter_SelectedIndexChanged(object sender, EventArgs e)
{
SetDefaultPrinter(cmbPrinter.SelectedText);
}
#endregion

C# 默认打印机设置

标签:code   each   str   bin   imp   set   prope   contains   vat   

原文地址:https://www.cnblogs.com/limitpjz/p/11232565.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!