You can directly press “Alt + PrtSc” to copy image of any active window to clipboard which you can paste in any Image Editor Program like Paint, Photoshop etc.. If you just need to have image of your Windows Form of your application, you can either use the upper technique, but you can also use simple code to capture image of your Windows Form which will also create an image file in your disk.
Instruction:
- Open Visual Studio and write code where you want e.g in a button click event, by following some instructions give below.
- First of all you need to set boundary limits of your image which for simple case will be the height and width of your Form and also X and Y location of starting point of your Form in the whole screen. You can directly use the following statement to save this all information in Rectangle variable.
Rectangle form = this.Bounds;
- Now create a new Bitmap variable which will be having dimensions same as that of the rectangle we defined above.
Bitmap bitmap = new Bitmap(form.Width, form.Height);
- Now create a graphic variable from the specified image which we declared (Bitmap) above.
Graphics graphic = Graphics.FromImage(bitmap);
- Use this graphic to copy an image by specifying boundaries of image and the starting point of image in X and Y coordinates.
graphic.CopyFromScreen(form.Location, Point.Empty, form.Size);
- Now save the image to desired location using the following command, by mentioning the format of image.
bitmap.Save("D://test.jpg", ImageFormat.Jpeg);
Now, Here Is my full code for this problem, This code was in Button Click Event, So it take image of my Form.
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);
}
Incoming search terms:
- c# capture form output to image (1)
- c# save clipboard image to bmp (1)
- capture form image clipboard vb6 (1)
- saving form as image c# (1)
In the above code” bitmap.Save(“D://test.jpg”, ImageFormat.Jpeg)”
there is no need to declare ” ImageFormat.Jpeg ” because if you included this then Visual studio will show build error.
also this code did not take screen shots from different parts mean to say that if you want to capture your systems current screenshot it will not allow you to do so.
thanks