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

How to make image of the form as it is on your drive on one button click using System.Drawing.Graphics

Author: DevASP
Download Source Code :

You can make bmp file of the form and it contains exact image of the form. This is very easy in the Visual Studio.Net.

To do this there are some simple steps. First create a project of VB then drag and label on the form having text Path then create a textbox with name txtpath and having text c:\myform1 as default text and a button with text Save. Now import System.Runtime.InteropServices by writing this on top the project VB file


Imports System.Runtime.InteropServices


Now write code on the button click event


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


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)




'saves image to c drive wrt name of the form

MyImage.Save(txtpath.Text & ".bmp")


End Sub

  • This is the simple code for this but there is a little code which is needed for BitBlt function


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


' Leave function empty - DLLImport attribute forwards calls to MoveFile to

' MoveFileW in KERNEL32.DLL.

End Function

  • Now this is the complete code for this purpose.



This is very simple code with which you can make exact image of your form.

Add Article Comment:
Name :
Email Address :
Comments :
<< How to Empty recycle bin using VB.NET

Disclaimer - Privacy
© 2002-2017