控件或窗体存为图片

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 @ 2009-03-04 21:27  YaSin  阅读(173)  评论(0)    收藏  举报