绘制控件到图片

本文介绍如何使用VS2005中的DrawToBitmap函数将窗体或DataGridView控件的内容保存为位图文件。通过实例展示了如何创建Bitmap对象并调用控件的DrawToBitmap方法来捕获其显示内容。
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); 

转载于:https://www.cnblogs.com/humors/archive/2008/10/16/1312636.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值