绘制控件到图片

vs2005里面给控件提供了DrawToBitmap函数  
  例如:   
   
//保存窗体到图片   
Bitmap   formBitmap   =   new   Bitmap(this.Width,   this.Height);   
this.DrawToBitmap(formBitmap,   new   Rectangle(0,   0,   this.Width,   this.Height));   
formBitmap.Save(
@"d:\form.bmp",   ImageFormat.Bmp);   

//保存控件DataGridView到图片   
Bitmap   controlBitmap   =   new   Bitmap(this.dataGridView1.Width,   this.dataGridView1.Height);   
this.dataGridView1.DrawToBitmap(controlBitmap,   new   Rectangle(0,   0,   this.dataGridView1.Width,   this.dataGridView1.Height));   
controlBitmap.Save(
@"d:\control.bmp",   ImageFormat.Bmp); 
posted @ 2008-03-18 14:30  小y  阅读(1036)  评论(2编辑  收藏  举报