C# – How to get a screen capture of a .Net WinForms control programmatically


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

Best Answer

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);