Search code examples
c#.netimagewinformscapture

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


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


Solution

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