简体   繁体   中英

Instant printing Visual Studio 2013 C#

Is there any method to print a document just by pressing PRINT button? I have to choose the printer first in order to proceed but I need to do this instantly.

[WindowsFormsApp]

Thanks!

I need 50 reputation to write comments, so i will write an answer.

As i can asume you are using the PrintDialog Class, try using the PrintDocument Class. Further information for the PrintDocument Class: https://msdn.microsoft.com/de-de/library/system.drawing.printing.printdocument(v=vs.110).aspx

With the PrintDocument Class you can set your printername so you dont have to show the Dialog.

using System.Drawing.Printing;

PrintDocument pd = new PrintDocument();
pd.PrinterSettings.PrinterName = "my printer";

To find your Installed printernames use this:

foreach (string s in PrinterSettings.InstalledPrinters) {
//
}

If you dont want to use the PrintDocument use this:

PrintDialog pd = new PrintDialog();
pd.PrintQueue = new PrintQueue(new PrintServer(), "printer name" );

But you have to remove ShowDialog() for this.

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