如何在执行打印预览时阻止出现"打印进度"对话框

Bry*_*yan 5 .net c# printing system.drawing

在我的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;
}
Run Code Online (Sandbox Code Playgroud)

除了显示打印预览进度对话框之外,打印预览完全按照我的要求工作.

建议好吗?

Mat*_*sen 6

这对我有用:

将文档的printcontroller设置为a 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));
        }
    }
Run Code Online (Sandbox Code Playgroud)


Bry*_*yan 2

我讨厌回答自己的问题,但解决方案就在我面前。

由于我已经编写了打印送货单的功能,因此我的下一步是提供屏幕副本(即无意打印硬拷贝)。打印预览对话框似乎是一个简单的出路。

最后,我只是创建了一个自定义表单并直接在其上绘制,看不到打印预览控件。

不幸的是,我过于专注于尝试让打印预览对话框按照我想要的方式运行,而不是着眼于更大的问题。