How to get a screen capture of a .Net WinForms control programmatically?

user34787 picture user34787 · Nov 5, 2008 · Viewed 25.5k times · Source

How do you programmatically obtain a picture of a .Net control?

Answer

user1228 picture user1228 · Nov 5, 2008

There's a method on every control called DrawToBitmap. You don't need to p/invoke to do this.

Control c = new TextBox();
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(c.Width, c.Height);
c.DrawToBitmap(bmp, c.ClientRectangle);