在我的 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;
}
除了显示打印预览进度对话框之外,打印预览完全符合我的要求。
有什么建议吗?
最佳答案
这对我有用:
将文档的 printcontroller 设置为 StandardPrintController
。
static class Program
{
static void Main()
{
PrintDocument doc = new PrintDocument();
doc.PrintController = new StandardPrintController();
doc.PrintPage += new PrintPageEventHandler(doc_PrintPage);
doc.Print();
}
static void doc_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawString("xxx", Control.DefaultFont, Brushes.Black, new PointF(e.PageBounds.Width / 2, e.PageBounds.Height / 2));
}
}
关于c# - 如何防止在执行打印预览时出现“打印进度”对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1357271/