How to Capture a Screen in VB
Beginning Visual Basic.NET developers may be surprised to discover that there is no obvious function to capture copies of the content currently on the screen, show it to the user and save it to the disk. Achieving the task is easy, but it is fairly counter-intuitive: rather than call a dedicated function, you need to simulate the use of the "Print Screen" key on the keyboard.
Instructions
-
-
1
Create a new project and select "Windows Forms Project."
-
2
Drag a Button and a Picturebox into your project from the Toolbox.
-
-
3
Double-click the button you added to create a "click" event for it.
-
4
Paste the following into the "Button1_Click" event that just appeared:
SendKeys.Send("%{PRTSC}")
Application.DoEvents()
Dim screen = Clipboard.GetDataObject
Dim bmp = CType(screen.GetData(GetType(System.Drawing.Bitmap)), Bitmap)
PictureBox1.Image = bmp
PictureBox1.Image.Save("C:\image.jpg")
Going line by line, this simulates a "Print Screen" key press (which is the shortcut key for creating screen shots). It then grabs the image data from the clipboard and displays it on the screen in the PictureBox. Finally, it saves it to the disk as a JPG.
-
1