简体   繁体   English

如何在C#中执行打印命令

[英]How to execute the print command in C#

At the beginning of this document , it says you can right-click on a file and print from there. 本文档的开头,它说您可以右键单击一个文件并从那里打印。 Now my question is, how do I print using C#? 现在我的问题是,如何使用C#打印? I can call the executable and give it the print command and the file, and it prints. 我可以调用可执行文件,并给它打印命令和文件,然后进行打印。 I can call the file directly, and it opens. 我可以直接调用该文件,它将打开。 But how do I call the file, and tell it to print? 但是,如何调用文件并告诉它打印?

Here is my current code, which requires knowing where the program is. 这是我当前的代码,需要知道程序在哪里。

ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = PathToProgram;
psi.Arguments = "/P \"" + PathToFile + "\"";
psi.UseShellExecute = false;
Process.Start(psi).WaitForExit();

Ok, I got it. 好,我知道了。 This is exactly what I was looking for. 这正是我想要的。 Notice the Verbs property. 注意动词属性。 It lists the different options you have to work with for that program. 它列出了该程序必须使用的不同选项。

ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = Program.appdata.PathToBillItemsLabels;
//Break. psi.Verbs = { "Open", "Print" };
psi.Verb = "Print";
Process.Start(psi).WaitForExit();
psi.UseShellExecute = true;

You must change the property to TRUE to work properly. 您必须将属性更改为TRUE才能正常工作。 Regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM