日期:2014-05-19  浏览次数:20812 次

求解,Graphics绘制当前窗体为图片,然后打印该图片
RT,求解!

------解决方案--------------------
Bitmap bit = new Bitmap(this.Size.Width, this.Size.Height);
this.DrawToBitmap(bit, new Rectangle(0,0, this.Width, this.Height));
bit.Save( "D:\\a.bmp ");

然后打印这个a.bmp就可以了.
------解决方案--------------------
寒... 这样的要求
------解决方案--------------------
你可以通过重写OnPrint方法来达到自定义的绘制,比如:
protected override void OnPrint(PaintEventArgs e)
{
base.OnPrint(e);
e.Graphics.DrawString( "我的一个测试 ", this.Font, SystemBrushes.ControlDark, 0, 0);
}

------解决方案--------------------
int height = System.Windows.Forms.SystemInformation.CaptionHeight;
Bitmap bit = new Bitmap(this.Width , this.Height);
this.DrawToBitmap(bit, new Rectangle(0,0,this.Width ,this.Height));

Bitmap b = new Bitmap(bit.Width, bit.Height - height);
Graphics g = Graphics.FromImage(b);
g.DrawImage(bit, new Rectangle(0, 0, b.Width, b.Height), new Rectangle(0, height, bit.Width, bit.Height - height), GraphicsUnit.Pixel);
b.Save( "D:\\a.bmp ");
bit.Dispose();
b.Dispose();