C# 默认打印机设置
Posted limitpjz
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C# 默认打印机设置相关的知识,希望对你有一定的参考价值。
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# 默认打印机设置的主要内容,如果未能解决你的问题,请参考以下文章