How to skip the dialog of printing in printDocument.print() and print page directly?

≡放荡痞女 提交于 2019-11-26 09:56:50

问题


When I use MyPrintDocument.print() in a Windows application written in C#, a dialog is shown for the Windows processing print routine with a cancel button. I don\'t want this dialog shown, is it possible?

If not, which way should I use? My program uses a thermal printer.


回答1:


Which PrintController are you using.

The .NET Framework includes three print controllers that are derived from PrintController that help accomplish common tasks. The StandardPrintController prints a document to a printer. The PreviewPrintController generates a preview of what the document will look like when printed and is used by the PrintPreviewControl and PrintPreviewDialog classes. The PrintControllerWithStatusDialog provides a printing status dialog during the printing process.

It sounds like you are using the PrintControllerWithStatusDialog PrintController.


Caveat: I am not in a position to verify that the basic PrintController doesn't act the same way.

According to this MSDN Forum Posting the PrintControllerWithStatusDialog is the default:

He suggests something like this:

MyPrintDocument.PrintController = new System.Drawing.Printing.StandardPrintController();



回答2:


If you don't assign the PrintDocument.PrintController property then you get a default print controller. An instance of PrintControllerWithStatusDialog which displays the progress dialog, counting pages and generally informing the user that the program is unresponsive for a reason but otherwise not hung.

Simply reassign it in the form constructor. Boilerplate code is:

Public Class Form1
    Public Sub New()
        InitializeComponent()
        PrintDocument1.PrintController = New System.Drawing.Printing.StandardPrintController
    End Sub
End Class

And you'll have to do something else to tell the user that a print is in progress. At least display an hourglass cursor.



来源:https://stackoverflow.com/questions/10572420/how-to-skip-the-dialog-of-printing-in-printdocument-print-and-print-page-direc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!