Promote Your Blog

Monday, January 16, 2012

How To Capture Screen Using VB

Suppose your screen capturing tool has a form with a button control on it. Then, simply add following code to callback function of Button control:

Dim bounds As Rectangle
Dim screenshot As System.Drawing.Bitmap
Dim graph As Graphics

bounds = Screen.PrimaryScreen.Bounds
screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(screenshot)
graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)


Me.Hide() hides the form momentarily to allow capturing complete screen including underneath of this form.
Code has been taken from some forum on Internet and added line '"img.jpg")' so that capture image can be saved. Unless, path is specified, the image will be saved in the directory from where executable is run.

No comments:

Post a Comment