您好我正在我的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);
}
请让我知道如何解决这个问题
提前致谢
答案 0 :(得分: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);
}