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

前端 未结 7 1330
生来不讨喜
生来不讨喜 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

    The easiest way I found is to create a new PrinterSettings object. It starts with all default values, so you can check its Name property to get the name of the default printer.

    PrinterSettings is in System.Drawing.dll in the namespace System.Drawing.Printing.

    PrinterSettings settings = new PrinterSettings();
    Console.WriteLine(settings.PrinterName);

    Alternatively, you could maybe use the static PrinterSettings.InstalledPrinters method to get a list of all printer names, then set the PrinterName property and check the IsDefaultPrinter. I haven't tried this, but the documentation seems to suggest it won't work. Apparently IsDefaultPrinter is only true when PrinterName is not explicitly set.

提交回复
热议问题