我有这个打印标签的例程,无论是在屏幕上的预览模式下还是在标签打印机上。在每个打印操作开始之前,屏幕上会短暂显示一个令人讨厌的对话框,该对话框标有“正在打印”,并且在正文中显示“文档的第 1 页”和“取消”按钮。我发现一个参考资料说我可以在打印之前使用如下语句来消除这种情况:
MyPowderlabel.PrintController = new System.Drawing.Printing.StandardPrintController();
这似乎没有任何效果。
这是代码:
private void PrintLabel(object sender, EventArgs e)
{ // This routine starts up the print operation for the current label
try
{
PrintDocument MyPowderlabel;
MyPowderlabel = new PrintDocument();
PaperSize PS = null; //Label dimensions for printer are in units of .01"
PS = new PaperSize("Custom Size", 134, 118 ); // 3.4 cm wide x 3 cm high
MyPowderlabel.DefaultPageSettings.PaperSize = PS;
MyPowderlabel.DefaultPageSettings.Landscape = false;
MyPowderlabel.PrintPage += new PrintPageEventHandler(MyPowderlabel_PrintPage);
MyPowderlabel.PrinterSettings.PrinterName = printersList.Text;
// Display the label in the print preview box
printPreviewControl1.Document = MyPowderlabel;
printPreviewControl1.Document.PrintController = new System.Drawing.Printing.StandardPrintController();
printPreviewControl1.Show();
//The next statement is needed to insure that the label preview will be displayed for at least
//a short time before it gets erased before the next barcode is processed.
Application.DoEvents();
if (!ckPrintPreview.Checked)
{
// Send the label to the selected (hard copy) printer
MyPowderlabel.PrintController = new System.Drawing.Printing.StandardPrintController();
MyPowderlabel.Print();
}
}
catch (Exception EX)
{
MessageBox.Show("Error while trying to send label to printer\r\n" + EX.Message);
}
}