Monday, August 04, 2008

snapshot C# using PaintEventArgs

In RichFocus we had a problem to get the control image. We used old print screen methods to do this before, and it captures the whole thing with the windows on top of the control ... so I decided to use the OnPaint method to re-draw it for us.


// Inside snapshot control ...
Rectangle rect = this.ClientRectangle;

//create an empty image with the same size of the control
Bitmap bmp = new Bitmap(rect.Width, rect.Height);

Graphics g = Graphics.FromImage(bmp);

PaintEventArgs p= new PaintEventArgs(g, rect);

// paint the background,
this.InvokePaintBackground(this, p);

// this will invoke the control paint method
this.InvokePaint(this, p);

No comments: