GetScreenSnapshot - Retrieving the current contents of the screen or the active window
' Return the current contents of the screen or the active window
' It works by simulating the typing of the Print-Screen key (and Alt key if
' activeWindowOnly is True), which dumps the screen to the clipboard.
'
' Example: PictureBox1.Image = GetScreenSnapshot(True)
Function GetScreenSnapshot() As Image
Return GetScreenSnapshot(False)
End Function
Function GetScreenSnapshot(ByVal activeWindowOnly As Boolean) As Image
' Alt-Print Screen captures the active window only
If activeWindowOnly Then
SendKeys.SendWait("%{PRTSC}")
Else
SendKeys.SendWait("{PRTSC 2}")
End If
' return the bitmap now in the clipboard
Return DirectCast(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), _
Image)
End Function