简体   繁体   中英

C# - take picture from inside of a form

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.

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 (eg 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); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM