Screenshot Application in VB.NET

If you’ve got a problem with a program, you may be wondering how to show someone the errors you’re receiving. Luckily, taking a screenshot of your current display is just very simple in only pressing the 'PrintScreen' in your Keyboard. but there's one way to do this because we will make an application that captures your screen. So, now let's start this tutorial! 1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application. 2. Next, add one Button named Button1 labeled as "Capture Screen". You must design your layout like this: design 3. Next, put this code in Button1_Click so that it will capture your screen.
  1. On Error GoTo err
  2. Dim shot As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
  3. Dim grab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
  4. Dim s As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(grab)
  5. s.CopyFromScreen(New Point(0, 0), New Point(0, 0), shot)
  6. grab.Save("screenshot.jpg")
  7. MsgBox("Your screenshot was saved", MsgBoxStyle.Information)
  8. Me.Close()
  9. err:
  10. MsgBox("sorry unable to snap your screen and save at the moment please try again later", MsgBoxStyle.Critical, "Warning!")
  11.  
  12. End Sub

Explanation:

On Error GoTo err - this was the syntax that i had lectured a day ago. This syntax is for error handling that it will go to the variable err which will display "sorry unable to snap your screen and save at the moment please try again later". Dim shot As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height) - this syntax initializes shot as the size of your computer screen. Last day I discussed about My namespace that it provides information regarding your computer.  Dim grab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height) - this syntax initializes to create an image that corresponds to the size of your screen that will pass through the variable grab. Dim s As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(grab) - this syntax holds the image that we create using the variable 'grab'. This syntax also has the Graphics to be passed through the variable 's'.
  1. s.CopyFromScreen(New Point(0, 0), New Point(0, 0), shot)
  2. grab.Save("screenshot.jpg")
  3. MsgBox("Your screenshot was saved", MsgBoxStyle.Information)
The above syntax copies the image in your screen and will save as "screenshot.jpg". It will be saved also in your Debug Folder in your program and will display "Your screenshot was saved". Now, click the Capture Button. It will display like the image below: output Next, Go to your Debug Folder and you will have your image.

Output:

screenshot Download the source code below and try it! :) For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards,

Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]

Visit and like my page on Facebook at: Bermz ISware Solutions

Subscribe at my YouTube Channel at: SerBermz

Comments

Submitted bymikeF (not verified)on Wed, 11/17/2021 - 09:11

Thank you. This worked great in my VB.net 2019 application. I added Me.Hide( ) before the grab, and Me.Show ( ) after the grab in order to hide my application (the other windows were the important stuff).

Add new comment