0

嗨,我正在我的 Windows 应用程序中打印一个面板。当我单击打印面板时,它在我单击打印对话中的打印后打开打印对话框,它会引发异常。

System.CompoentModel.Win32Exception{"Access is denied"}

这是我正在使用的代码。

Bitmap MemoryImage;

    private void btnPrint_Click(object sender, EventArgs e)
    {
        panel1.BackColor = Color.White;
        printDialog1.Document = printDocument1;

        if (printDialog1.ShowDialog() == DialogResult.OK)
        {
            printDocument1.Print();
        }
    }

    private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
    {
        Rectangle pagearea = e.PageBounds;
        e.Graphics.DrawImage(MemoryImage, (panel1.Width / 2) - (this.panel1.Width / 2), this.panel1.Location.Y);

    }

请让我知道如何解决这个问题

提前致谢

4

1 回答 1

0

试试看

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            System.Drawing.Bitmap MemoryImage = new System.Drawing.Bitmap(panel1.Width, panel1.Height);
            Rectangle pagearea = e.PageBounds;
            panel1.DrawToBitmap(MemoryImage, panel1.ClientRectangle);
            e.Graphics.DrawImage(MemoryImage, (pagearea.Width / 2) - (this.panel1.Width / 2), this.panel1.Location.Y);
        }
于 2013-05-24T10:07:07.460 回答