如何在打印文档之前等待表单完全加载

时间:2018-07-19 12:26:23

标签: c# .net winforms

我正在使用“打印文档”来捕获表单的屏幕截图,并在加载后立即打印。我已经使用了“显示形式”事件,但是图像仍然部分加载出来!我该怎么办才能帮助它正确打印。

    Bitmap bmp;

    public void initiatePrint()
    {
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

        Graphics g = this.CreateGraphics();
        bmp = new Bitmap(this.Size.Width, this.Size.Height, g);
        Graphics mg = Graphics.FromImage(bmp);
        mg.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, this.Size);
        printPreviewDialogPrint.ShowDialog();

        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
    }

    private void printDocument1_PrintPage_1(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
        e.Graphics.DrawImage(bmp, (e.PageBounds.Width - bmp.Width) / 2, (e.PageBounds.Height - bmp.Height) / 2, bmp.Width, bmp.Height);
    }

    private void FPrint_Shown(object sender, EventArgs e)
    {
        initiatePrint();
    }

这是我的打印代码。

0 个答案:

没有答案