Here’s a simple code, which enables save the form and other control as bitmap. This is very use full for the project documentation as well as for the reports. “DrawToBitmap” method provided for all the windows controls, which is used to perform this operation. Also we are not creating any “graphics”
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { SaveAsBitmap(this,"C:\\f1.bmp");
//The same way you can pass the controls like button,dataGrid etc //SaveAsBitmap(mydataGrid,"C:\\report.bmp") }
public void SaveAsBitmap(Control control, string fileName) { //getthe instance of the graphics from the control Graphics g = control.CreateGraphics(); //new bitmap object to save the image Bitmap bmp = new Bitmap(control.Width, control.Height);
//Drawing control to the bitmap control.DrawToBitmap(bmp, new Rectangle(0, 0, control.Width, control.Height)); bmp.Save(fileName); bmp.Dispose(); } }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|