如何设置为默认打印机
如何将 PrintDocument.PrinterSettings.PrinterName
设置为默认打印机?
我不是在谈论在操作系统中设置默认打印机。相反,我讨论的是设置 PrintDocument 对象,以便它打印到默认打印机。
How do you set PrintDocument.PrinterSettings.PrinterName
to be the default printer?
I am not talking about setting the default printer in the operating system. Rather, I am talking about setting the PrintDocument object so that it prints to the default printer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果我理解正确,您希望能够将 PrinterName 重置为默认打印机(1),而无需重新创建 PrintDocument , (2)在您可能已经将其设置为其他内容之后 或者, (3) 当默认打印机自首次创建 PrintDocument 以来可能已更改 < em>(因此您不能仅仅依赖于在初始构建后简单地缓存目标实例提供的默认值)。
在这种情况下,搜索“C# get default Printer name”会在 stackoverflow 上找到以下优秀帖子:在 .NET 中获取默认打印机的最佳方法是什么
基于投票最高的答案中提供的示例并考虑到您已经有一个预先存在的
PrintDocument
,其中包含一些您不想重新创建的设置;您可以创建PrinterSettings
类的新实例,其唯一目的是复制默认打印机名称。您可以查看链接的帖子以了解 WMI 等替代技术,但我认为这对您来说是最简单、最干净的解决方案。
If I'm understanding correctly, you would like to be able to reset the PrinterName to the default printer (1) without recreating your PrintDocument and, (2) after you may have already set it to something else or, (3) when the default printer may have changed since the time when the PrintDocument was first created (so you can't rely on simply caching the defaults provided by the target instance after initial construction).
In this case a search for "C# get default printer name" turns up the following excellent post on stackoverflow: What's the best way to get the default printer in .NET
Building on the sample provided in top voted answer and considering that you will already have a pre-existing
PrintDocument
with some settings you don't want to recreate; you could create a new instance of thePrinterSettings
class, for the sole purposes of copying out the default printer name.You can review the linked post for alternative techniques such as WMI, but I think this is the simplest and cleanest solution for you.
它会自动初始化为默认打印机。什么都不做。
It is automatically initialized to the default printer. Do nothing.
我假设您已在操作系统级别设置默认打印机。当您从代码启动打印时,它默认转到默认打印机。您不必明确设置它。
每个打印请求都会发生这种情况。我的意思是,如果您已将打印设置为另一台打印机,现在想要转到默认打印机,只需删除显式设置,它将再次转到默认打印机。
华泰
I assume you have set the default printer at the OS level. When you initiate a print from your code, it by defualt goes to Default Printer. You don't have to set it explicitly.
This happend for each print request. I mean if you have set the print to another printer and now you want to go to the default printer, just remove the explicit setting and it will again go to the default printer.
HTH
如果我错了,请纠正我,但您希望获取默认打印机的名称,然后将
PrintDocument.PrinterSettings.PrinterName
设置为此。当您使用
PrintDocument.PrinterSettings.PrinterName
时,默认情况下会使用默认打印机。Correct me if I am wrong but you are looking to get the name of the default printer and then setting
PrintDocument.PrinterSettings.PrinterName
to this.When you use
PrintDocument.PrinterSettings.PrinterName
this uses the default printer by default.默认情况下,如果您未在对象上设置任何内容,您将登陆默认打印机。以下是您正在寻找的官方来源: MSDN 链接到 PrintDocument 类
标记示例上方的句子:“以下代码示例在默认打印机上打印名为 C:\My Documents\MyFile.txt 的文件。”
华泰
By default you would be landing on default printer if you do not set anything on your object. Here is the official source you were looking for: MSDN Link to PrintDocument Class
Mark the sentence written just above the example: "The following code example prints the file named C:\My Documents\MyFile.txt on the default printer."
HTH