简体   繁体   中英

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#? 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. Regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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