Some way to capture a screen?

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

Is there some way to capture a screen in VB.Net?

I want to be able to capture the screen and write it to a record in a .mdb
(i.e. Access database) file when an error occurs but I have no idea how
exactly to do that. Alternatively writing it to a file in a directory would
be OK as well.

Any ideas how to go about this?
 
Here is code that uses Interop to capture a snapshot of a control.


Imports System.Runtime.InteropServices
Imports System.Drawing
Imports System.Drawing

Friend Class NativeMethods

<DllImport("user32.dll")> _
Public Shared Function GetDesktopWindow() As IntPtr
End Function

<System.Runtime.InteropServices.DllImport("user32.dll")> _
Public Shared Function GetWindowDC(ByVal hwnd As IntPtr) As IntPtr
End Function

<System.Runtime.InteropServices.DllImport("gdi32.dll")> _
Public Shared Function BitBlt(ByVal hDestDC As IntPtr, ByVal x As
Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As
Integer, ByVal hSrcDC As IntPtr, ByVal xSrc As Integer, ByVal ySrc As
Integer, ByVal dwRop As System.Int32) As UInt64
End Function
End Class 'NativeMethods

'Save the SnapShot capture into a jpg
Private Sub SnapShot(ByVal c as Control)
Dim myImage = New Bitmap(c.Width, c.Height)
Dim gr1 As Graphics = Graphics.FromImage(myImage)
Dim dc1 As IntPtr = gr1.GetHdc()
Dim dc2 As IntPtr = NativeMethods.GetWindowDC(c.Handle)
NativeMethods.BitBlt(dc1, 0, 0, c.Width, c.Height, dc2, 0, 0,
13369376)
gr1.ReleaseHdc(dc1)
myImage.Save("snapshot.jpg", ImageFormat.Jpeg)
End Sub 'SaveScreen


=======================================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
This is a old post from
Tim Wilson
Windows Embedded MVP

Re: Making a ("screenshot") image of a single control

is C# but the main idea is the use of API, and you can use for more than the
entery screen, you can youse this one for every control

MP

he say:

Funny you should ask. I just recently finished a utility library to do this,
as well as take a screen capture if desired. The code has been adapted from
the source found here:
http://www.codeproject.com/csharp/csCaptureScreen1.asp. The attached zip
contains a solution with both the utility code and a form to demo. Just run
the solution to check it out.
 
Herfreid,

WOW, that is a fantastic solution, thank you very much! That does exactly
what I want.

Thank you!

--Mark
 
Back
Top