日期:2014-05-18  浏览次数:20847 次

关于picuturebox打印问题
我要将界面上picturebox里面的图片打印出来
查阅了很多网上的资料,但是还是不行,打出来时空的。
希望各位帮帮忙!
我的代码是这样的:
private void button3_Click(object sender, EventArgs e)
  {
  printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.pd_PrintPage);
  printDocument1.Print();
  }
private void pd_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
  {
  Graphics g = new Graphics();
  g.DrawImage(pictureBox1.Image, 0, 0, pictureBox1.Image.Width, pictureBox1.Image.Height);
  } 
pictureBox1.Image 这个是已经有的

------解决方案--------------------
不要new Graphics,要使用参数里的Graphics:

C# code

private void pd_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) 
        { 
            Graphics g = e.Graphics; 
            g.DrawImage(pictureBox1.Image, 0, 0, pictureBox1.Image.Width, pictureBox1.Image.Height); 
        }