简体   繁体   English

如何跳过printDocument.print()中的打印对话框并直接打印页面?

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

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. 当我在用C#编写的Windows应用程序中使用MyPrintDocument.print() ,将为Windows处理对话框显示一个带有取消按钮的对话框。 I don't want this dialog shown, is it possible? 我不希望显示此对话框,可以吗?

If not, which way should I use? 如果没有,我应该使用哪种方式? My program uses a thermal printer. 我的程序使用热敏打印机。

Which PrintController are you using. 正在使用哪个PrintController

The .NET Framework includes three print controllers that are derived from PrintController that help accomplish common tasks. .NET Framework包括三个从PrintController派生的打印控制器,它们可以帮助完成常见任务。 The StandardPrintController prints a document to a printer. StandardPrintController将文档打印到打印机。 The PreviewPrintController generates a preview of what the document will look like when printed and is used by the PrintPreviewControl and PrintPreviewDialog classes. PreviewPrintController生成打印时文档外观的预览,并由PrintPreviewControlPrintPreviewDialog类使用。 The PrintControllerWithStatusDialog provides a printing status dialog during the printing process. PrintControllerWithStatusDialog在打印过程中提供打印状态对话框。

It sounds like you are using the PrintControllerWithStatusDialog PrintController . 听起来您正在使用PrintControllerWithStatusDialog PrintController


Caveat: I am not in a position to verify that the basic PrintController doesn't act the same way. 警告:我无法验证基本的PrintController不会以相同的方式运行。

According to this MSDN Forum Posting the PrintControllerWithStatusDialog is the default: 根据此MSDN论坛 ,默认情况下, 发布 PrintControllerWithStatusDialog

He suggests something like this: 他建议如下:

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

If you don't assign the PrintDocument.PrintController property then you get a default print controller. 如果不分配PrintDocument.PrintController属性,则将获得默认的打印控制器。 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. 一个PrintControllerWithStatusDialog的实例,它显示进度对话框,对页面进行计数,并通常通知用户该程序由于某种原因没有响应,但没有挂起。

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 . 至少显示一个沙漏光标

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

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