What's the best way to get the default printer in .NET

前端 未结 7 1315
生来不讨喜
生来不讨喜 2020-12-07 12:58

I need to get the default printer name. I\'ll be using C# but I suspect this is more of a framework question and isn\'t language specific.

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-07 13:48

    I use always in this case the System.Printing.LocalPrintServer, which makes also possible to obtain whether the printer is local, network or fax.

    string defaultPrinter;
    using(var printServer = new LocalPrintServer()) {
      defaultPrinter = printServer.DefaultPrintQueue.FullName);
    }
    

    or using a static method GetDefaultPrintQueue

    LocalPrintServer.GetDefaultPrintQueue().FullName
    

提交回复
热议问题