Thought i’d post this as it came in handy on a recent project i was involved in. You may need to tweak the offsets if the form is a child of a parent form.

[codesyntax lang=”vbnet”]

    Private Sub GetScreenshot()
        Dim graph As Graphics = Nothing
        Try
            Dim frmleft As System.Drawing.Point = Me.Bounds.Location

            Dim bmp As New Bitmap(Me.Bounds.Width + 10, Me.Bounds.Height + 10)

            graph = Graphics.FromImage(bmp)

            Dim screenx As Integer = frmleft.X
            Dim screeny As Integer = frmleft.Y

            graph.CopyFromScreen(screenx - 5, screeny + 45, 0, 0, bmp.Size)

            bmp.Save("c:\screenshot.png")
            Application.DoEvents()
            System.Threading.Thread.Sleep(2000)

            bmp.Dispose()
            graph.Dispose()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

[/codesyntax]

Leave a reply

Your email address will not be published.