3

OK, I know how DrawToBitmap works or the CopyToScreen methods and all. What I'm looking for is how to take a picture from inside a form (without the form borders, title and maximize box and all) I tried different things for the Rectangle parameter of the DrawToBitmap method but none worked and I just can't figure it out. I appreciate any help.

Auxiliary
  • 2,687
  • 5
  • 37
  • 59

1 Answers1

2

Well, you have two choices:
1) Go into complex Windows API's
2) Take a screenshot and simply cropping out the form.
1 is probably faster and will work even if something is hiding the form (e.g an other form)
2 will only work if there's nothing hiding the form, and its in the screen.
Well, you can use this code if you like:

Rectangle form = this.Bounds; 
using (Bitmap bitmap = new Bitmap(form.Width, form.Height)) 
{ 
    using (Graphics graphic = 
        Graphics.FromImage(bitmap)) 
    { 
        graphic.CopyFromScreen(form.Location, 
            Point.Empty, form.Size); 
    } 
    bitmap.Save("D://test.jpg", ImageFormat.Jpeg); 
}
Mark Segal
  • 5,427
  • 4
  • 31
  • 69
  • 2
    Do you know where I can find documentation pertaining to the first option? I use the second option in an application but I need to be able to take pictures of a certain form even if it's occluded by something else. – Mike Bailey Jul 16 '11 at 23:47