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