+92 332 4229 857 99ProjectIdeas@Gmail.com

How to take ScreenShot (Vb.net)

The following code shows you how to take the screen shot, first you have browse where to save the screen shot after taken, write the name and then press save . Now after doing this press the capture button and screen is captured and shows you the path where it is saved and then after open the captured image in windows picture viewer.

Imports System.Drawing.Graphics

Dim path As String = String.Empty

Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click

        With SaveFileDialog1
            If .ShowDialog() = DialogResult.OK Then
                path = .FileName
            End If
        End With
End Sub

'Saving the image as .jpg extension
 Dim saveFile As String = path & ".jpg"

 Dim screenSize As New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)

 Dim capImage As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)

 Dim graph As Graphics = Graphics.FromImage(capImage)

 graph.CopyFromScreen(New Point(0, 0), New Point(0, 0), screenSize)


 MsgBox("Saved File To : " & saveFile) 'Showing the whole path where capturedImage is saved

 Process.Start(saveFile) 'Showing The Captured Image In Windows Image Viewer