2013-04-05 38 views
0

嗨,我在Windows应用程序中打印面板。当我点击打印面板后,它打开打印对话框,我点击打印在打印dailog它是抛出一个异常。无法在c#窗口应用程序中打印面板

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

你在两个窗口得到这个XP以及Windows 7? 可能是用户访问控制问题 – 2013-04-05 07:28:41

+0

这与您的代码没有任何关系,它是您计算机上的配置问题。尝试使用另一台打印机来本地化问题,并要求您的LAN管理员或IT人员寻求帮助。 – 2013-04-05 10:47:45

回答

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); 
     } 
相关问题