【发布时间】:2010-11-24 08:14:50
【问题描述】:
在我的 C# 应用程序中,我试图在屏幕上不显示进度对话框的情况下生成打印预览。
我相信您可以在实际打印时使用PrintDocument.PrintController 来防止这种情况(即不是打印预览),但是在执行打印预览时它似乎不起作用。
我的代码如下:
public FrmDeliveryNotePrintPreview(DeliveryNote deliveryNote)
{
InitializeComponent();
this.Text = "Delivery Note #" + deliveryNote.Id.ToString();
// The print preview window should occupy about 90% of the
// total screen height
int height = (int) (Screen.PrimaryScreen.Bounds.Height * 0.9);
// Making an assumption that we are printing to A4 landscape,
// then adjust the width to give the correct height:width ratio
// for A4 landscape.
int width = (int) (height / 1.415);
// Set the bounds of this form. The PrintPreviewControl is
// docked, so it should just do the right thing
this.SetBounds(0, 0, width, height);
PrinterSettings printerSettings = new PrinterSettings();
PrintDeliveryNotes pdn = new PrintDeliveryNotes(
new DeliveryNote[] { deliveryNote },
printerSettings);
PrintDocument printDocument = pdn.PrintDocument;
printDocument.PrintController = new PreviewPrintController();
ppcDeliveryNote.Document = printDocument;
}
打印预览完全按照我的意愿工作,除了显示打印预览进度对话框。
请给点建议?
【问题讨论】:
-
PrintDeliveryNotes 是一个打印交货单数组的类。但在这种情况下,我没有调用 Print() 方法,而是简单地检索 PrintDocument 属性并将其提供给自定义表单上的 PrintPreviewControl。
标签: c# .net printing system.drawing