当前位置: 代码迷 >> 综合 >> 打印系统开发(38)——API(3)——windows设置默认打印机
  详细解决方案

打印系统开发(38)——API(3)——windows设置默认打印机

热度:11   发布时间:2023-10-01 14:55:49.0

实现这个功能需要使用windows api

[DllImport("winspool.drv")]
public static extern bool SetDefaultPrinter(String Name);
//调用win api将指定名称的打印机设置为默认打印机
private static PrintDocument PrintDocument = new PrintDocument();
public static void SetDefaultPrint(string printName) {List<string> stringList = new List<string>();foreach (var item in PrinterSettings.InstalledPrinters){stringList.Add(item.ToString());}// string  PrinterName = PrintDocument.PrinterSettings.PrinterName;//获取当前设置的打印机SetDefaultPrinter(stringList[0]);//使用win api函数设置默认打印机
}

  亲测运行成功

  相关解决方案