读书人

关于picuturebox打印有关问题

发布时间: 2011-12-24 23:03:24 作者: rapoo

关于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);         } 

读书人网 >C#

热点推荐