Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
hi how can capture screen part of form

like this : http://i62.tinypic.com/2z5t6pi.png[^]

C#
private void button2_Click(object sender, EventArgs e)
    {

    using (Bitmap bmp = new Bitmap(Width, Height))
        {
        using (Graphics g = Graphics.FromImage(bmp))
            {
            g.CopyFromScreen(this.Location.X, 
                             this.Location.Y, 
                             0, 
                             0, 
                             bmp.Size, 
                             CopyPixelOperation.SourceCopy);
            }

        bmp.Save(@"F:\printscreen.jpg", ImageFormat.Jpeg);
        }
    }

11
Posted
Updated 15-Jun-14 3:49am
v3
Comments
Sergey Alexandrovich Kryukov 15-Jun-14 21:03pm    
You have everything you want; and you are almost there. Just change location and size accordingly. What's the problem?
—SA

 
Share this answer
 
Comments
gggustafson 15-Jun-14 9:52am    
+5
Please see my comment to the question. All you need to do is to adjust location and the size of your client part of the window.

Most likely, you want to copy the non-client area of some window. So, the problem is reduced to calculation of the position and size of the client part. This methods/properties are enough to solve this problem.
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.clientrectangle(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.clientsize(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.pointtoclient(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.pointtoscreen(v=vs.110).aspx[^].

And also this class: http://msdn.microsoft.com/en-us/library/system.windows.systemparameters%28v=vs.110%29.aspx[^].

It also depends on what do you know about the window you want to copy.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900