Tag Archives: CopyFromScreen

Easy way to take a screenshot in VB 2008 and Visual Basic.NET 2010

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
 

The newer 2.0 version of the DotNET Framework added alot of new features. One of them is the ability to natively copy the visual contents of the screen. You can find this Sub() under the: System.Drawing.Graphics namespace named – ‘CopyFromScreen’. The ‘CopyFromScreen’ Sub has 4x overloads. You can specify the Destination coordinates to put the image and the Source coordinates to get the image. Also available is CopyPixelOperation which allows you to select the way you want to copy the pixels. System.Drawing.CopyPixelOperation.SourceCopy is the most common operation. Below is a simple demonstration to take a screenshot in your applications.

This basic sample only needs a picturebox.


'Copy the screen contents to the picturebox control. Select the X and Y positions to get the‘screens image,
'then select the X,Y positions to set the screen image to the picturebox control.
'You then simply specify how much of the image you want to copy. picScreen is the name of the picturebox I used.

picScreen.CreateGraphics.CopyFromScreen(0, 0, 0, 0, New Size(100, 100))