More Windows Secrets for Visual Basic

Capturing the Screen, Quick and Easy

When it comes to showing people how to capture the screen, most VB.NET authors I've seen tend to revert to the old-school method of working: using the API. There is, however, a better way.

The following function is called GetScreenCapture and returns an Image object. It captures the screen by running a series of "Print Screen" key presses, which puts a screen grab on the Clipboard, ready for my nifty little function to devour and return. My function accepts a FullScreen argument, too: Pass True to capture the whole screen, or False to capture just the active window.