Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering form to bitmap

I would like to render Form to bitmap... Is it possible in .net 2.0?

like image 882
Daniel Mošmondor Avatar asked Nov 23 '09 16:11

Daniel Mošmondor


1 Answers

Sure, you can call Control.DrawToBitmap() to render a control to a bitmap. For more general drawing, you can create a Bitmap and then use Graphics.FromImage() to create a Graphics instance. You can then draw to this graphics instance as normal.

Here's a simple form that can draw itself (just add a button and double click it to add the Click event handler:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Bitmap b = new Bitmap(Width, Height);
        DrawToBitmap(b, new Rectangle(0, 0, Width, Height));
        b.Save("Test.bmp");
    }
}
like image 137
Eric Avatar answered Sep 23 '22 01:09

Eric