什么是获得在.NET中的默认打印机的最佳方式 [英] What's the best way to get the default printer in .NET

查看:99
本文介绍了什么是获得在.NET中的默认打印机的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要得到默认的打印机名称。我会使用C#,但我怀疑这更多的是一个框架的问题,而不是特定的语言。

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.

推荐答案

我发现的最简单的方法是创建一个新的 PrinterSettings 对象。它从所有默认值,这样你就可以检查它的名称的属性来获取默认打印机的名称。

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 在System.Drawing.dll程序命名空间中的 System.Drawing.Printing

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

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

另外,你也许可以使用静态 PrinterSettings.InstalledPrinters 方法来获得所有的打印机名称的列表,然后设置的的PrinterName 的财产,检查的 IsDefaultPrinter 的。我没有试过,但文档似乎表明它不会工作。显然的 IsDefaultPrinter 的仅仅是真实的,当的的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.

这篇关于什么是获得在.NET中的默认打印机的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆