Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Capture And Save Form Using Interop and C#

Author: DevASP
Download Source Code : 458_Capture_save_from.zip

In this article I will try to explain how you can Capture the from and save it on your drive Using InteropServices and C#.

This is simple project which captures the form and save its image on the C drive. Create a new application in vb.net, set any background of the from and drag a button on it. Import the InteropServices as:

 

Imports System.Runtime.InteropServices

Once you imports the InteropServices then you can add the following code to use the DLL:

 

<DllImport("gdi32.DLL", EntryPoint:="BitBlt", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _

 

Private Shared Function BitBlt(ByVal hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As System.Int32) As Boolean

 

End Function

 

Now right the following code on the button click event:

 

Dim g1 As Graphics = Me.CreateGraphics()

Dim MyImage = New Bitmap(Me.ClientRectangle.Width, (Me.ClientRectangle.Height), g1)

Dim g2 As Graphics = Graphics.FromImage(MyImage)

Dim dc1 As IntPtr = g1.GetHdc()

Dim dc2 As IntPtr = g2.GetHdc()

BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, (Me.ClientRectangle.Height), dc1, 0, 0, 13369376)

g1.ReleaseHdc(dc1)

g2.ReleaseHdc(dc2)

MyImage.Save("C:\\From1.bmp")

MsgBox("Form1 is captured and save on C drive as From1.bmp",MsgBoxStyle.Information,"Form Saved")

Button1.Enabled = False

 

Article Comments
Hello,
I have TabControl which has 3 tabpages in it.Without go to the tabpage2 or tabpage3 i need to get the image .Tabpages contains some control like datagridview and PictureBox.Using c#

Posted on 8/23/2008 6:40:42 AM by vedavathi.HT

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Creating a ToolBar in Visual Basic.Net

Disclaimer - Privacy
© 2002-2017 DevASP.net