Question When 'Print Screen' button is pressed, Screenshot saved to desktop [Please Help]

xjamesfx

Member
Joined
Apr 3, 2011
Messages
12
Programming Experience
Beginner
Hi, I am looking to create simple application that means that when the
'Print Screen' button is pressed, the screenshot is not just sent to the clipboard but
saved to the desktop in either JPEG or PNG format.
The application will run at startup so that the 'new' print screen functionality
is there but the interface of the app is opened manually.
(the app interface includes simple options such as choose where file is saved.)

It would be greatly appreciated if anyone could help me out. Im very new to VB so any help is welcome.

Thanks alot.
 
You will probably want to hook the keyboard and watch for the PrtScn button(44) to be pressed, then use the My.Computer.Clipboard class to get the saved image. You will probably end up creating to EXE's, one that is always running to save the file, and another for the user interface.

Keyboard Hook example: [VB.net] Keyboard Hook Class « sim0n


Retrieving a image file from the clipboard and saving it:
VB.NET:
Dim img As Image = My.Computer.Clipboard.GetImage
img.Save("C:\screenshot1.png", System.Drawing.Imaging.ImageFormat.Png)

You will want to change the location of the file to the user defined location.

Hope this helps a little, let us know if you have any more questions!
-Josh
 
Thanks alot that really helped. You wouldnt happen to know how to make the screenshot number change by +1 every time a screenshot is taken?

Cheers.
 
You could just have a global variable that is incremented by 1 each time you call that save function.

Global Var:
VB.NET:
Dim intShots as Integer = 1

In your key event handler:
VB.NET:
Dim img As Image = My.Computer.Clipboard.GetImage
img.Save("C:\screenshot" & intShots & ".png", System.Drawing.Imaging.ImageFormat.Png
intShots += 1
 
I would use something like this because it will still work even if the program is restarted.

VB.NET:
 Dim i As Integer = 1
 Do Until Not File.Exists("C:\screenshot_" & i & ".png")
     i = i + 1
 Loop
 Dim img As Image = My.Computer.Clipboard.GetImage
 img.Save("C:\screenshot" & i & ".png", System.Drawing.Imaging.ImageFormat.Png)

-Josh
 
Back
Top