Hi Max,
The code below will capture the given Control's image and return a
BitMap.
This example captures the current Form (which is a Control itself)
Dim bmp As Bitmap
bmp = CaptureControl (Me)
bmp.Save ("FormX.bmp", Imaging.ImageFormat.Bmp)
Regards,
Fergus
<code>
Public Declare Function BitBlt Lib "gdi32" ( _
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 Integer _
) As Integer
'===================================================================
Public Function CaptureControl(ByVal c As Control) As Bitmap
Const SRCCOPY As Integer = &HCC0020
Dim bmp As Bitmap
Dim gDest, gSource As Graphics
Dim hdcSource, hdcDest As IntPtr
bmp = New Bitmap(c.Width, c.Height)
gSource = c.CreateGraphics
Try
gDest = Graphics.FromImage(bmp)
Try
hdcSource = gSource.GetHdc
Try
hdcDest = gDest.GetHdc
Try
BitBlt( _
hdcDest, 0, 0, _
c.Width, c.Height, _
hdcSource, 0, 0, SRCCOPY _
)
Finally
gDest.ReleaseHdc(hdcDest)
End Try
Finally
gSource.ReleaseHdc(hdcSource)
End Try
Finally
gDest.Dispose()
End Try
Finally
gSource.Dispose()
End Try
Return bmp
End Function
</code>