Ad Code

Responsive Advertisement

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:

Me.Hide()
Dim bounds As Rectangle
Dim screenshot As System.Drawing.Bitmap
Dim graph As Graphics

System.Threading.Thread.Sleep(200)
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)

screenshot.Save("img.jpg")
Me.Close()

---------
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 'screenshot.save("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.

Post a Comment

0 Comments