Hi There, Im using Vb.net Framework 4.
I was wondering wow do i take a screenshot of only an active windows....similar to the ALT+PrtScn. I would like to implement a screen capture for errors handling. I have current code that is able to take screenshots but it takes a screen capture of the entire primary monitor. Any Help or Guidances would be great.
Private Function TakeImage()
Return TakeImage(0, 0, Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height)
End Function
Private Function TakeImage(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer)
Dim Img As New Bitmap(Width, Height)
Dim g As Graphics = Graphics.FromImage(Img)
g.CopyFromScreen(X, Y, 0, 0, Img.Size)
g.Dispose()
Return Img
End Function
After having a look around googs abit more found handy bit of code for what im looking for....maybe it may help you. (The code basically takes a screenshot of the active window)
Dim bm As New Bitmap(Me.Width, Me.Height)
Dim g As Graphics = Graphics.FromImage(bm)
g.CopyFromScreen(Me.Location, New Point(0, 0), New Size(Me.Width, Me.Height))
bm.Save("C:\formgrab.bmp", Drawing.Imaging.ImageFormat.Bmp)