0% found this document useful (0 votes)
281 views

Gigemboy: Visual Basic Code From Freevbcode

A class that contains very easy methods to get screen captures. It was originally written in c#, and there was supposedly a VB.NET example in there. The file has its own namespace, "ScreenShot", which includes three seperate classes.

Uploaded by

dandx
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
281 views

Gigemboy: Visual Basic Code From Freevbcode

A class that contains very easy methods to get screen captures. It was originally written in c#, and there was supposedly a VB.NET example in there. The file has its own namespace, "ScreenShot", which includes three seperate classes.

Uploaded by

dandx
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

IT Professionals Developers Solutions eBook Library Webopedia Login Register

To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE. 
To participate in the message forums BELOW, click here

Visual Basic Code from FreeVBCode

Get and Set Word file Attributes with VB.NET 
Calculate Age in Visual Basic 2005, Counting Leap years 
Spatial Matrix Memory Game 
Introduction to Cryptoanalysis 
Linked List implementation in Visual Basic      
Submit your code to FreeVBCode

  VBForums  > VBForums C odeBank   > C odeBank ­ Visual Basic .NET User Name User Name Remember Me?


 Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls
Password Log in

Register FAQ Calendar Today's Posts VB Jobs Search

  Page 1 of 2 1 2 >

  Thread Tools Display Modes

 Feb 4th, 2006, 03:13
  #1
PM

gigemboy Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

"The" RedHeadedLefty
Here is a class that contains very easy methods to get screen captures. It is not code originally written by me, it was
 
actually found Here. It was originally written in C#, and there was supposedly a VB.NET example in there, however it just
looked as if it was ran through some code converter that didn't work. I cleaned it up in order for it to work in .NET, replaced
all the API declarations with the correct working ones, and even added a CaptureDeskTopRectangle function to it for
desktop regions.
 
Join Date: Aug 05
Location: C ollege Station,
The file has its own namespace, "ScreenShot", which includes three seperate classes:

open in browser customize free license pdfcrowd.com


Location: C ollege Station,
TX Preferred Nickname: Gig
C urrent Mood: Just Peachy ScreenCapture ­ Main class, contains functions for obtaining the actual images
Turnons: String GDI32 = Helper Class with various GDI Functions that are used
Manipulation USER32 ­ Helper Class with various User32 Functions used
Posts: 4,487
The ScreenCapture has five exposed functions and methods that enables you to get captures:

CaptureWindow ­ grabs image of object by its handle
CaptureScreen ­ grabs image of entire screen
CaptureWindowToFile ­ captures image of object by its handle straight to file
CaptureScreenToFile ­ captures image of screen straight to file
CaptureDesktopRectangle ­ captures desktop region by a passed in rectangle

***.NET 2005 has a .CopyFromScreen method in the Graphics class that allows you to get a desktop region, however,
there is no way in 2003, which is why CaptureDesktopRectangle was needed...

Sample code showing how to use each method is below, the class is available for download at the end of the post.
VB C ode:

1. Dim SC As New ScreenShot.ScreenCapture


2.
3. 'grabs image of object handle (in this case, the form)
4. Dim MyWindow As Image = SC.CaptureWindow(Me.Handle)
5.
6. 'grabs image of entire desktop
7. Dim MyDesktop As Image = SC.CaptureScreen
8.
9. 'captures entire desktop straight to file
10. SC.CaptureScreenToFile("c:\desktop2.jpg", Imaging.ImageFormat.Jpeg)
11.
12. 'captures image of object handle (in this case, the form) straight to file
13. SC.CaptureWindowToFile(Me.Handle, "c:\window2.jpg", Imaging.ImageFormat.Jpeg)
14.
15. 'returns bitmap of region of desktop by passing in a rectangle
16. Dim MyBitMap As Bitmap = SC.CaptureDeskTopRectangle(New Rectangle(Me.Location.X, Me.Location
17. Me.Width, Me.Height), Me.Width, Me.Height)
18. MyBitMap.Save("c:\desktopregion.jpg", Imaging.ImageFormat.Jpeg)
19. 'above example gets rectangle of form that it is called in, you can get
20. 'desktop by calling me.hide before the actual function call in order to
21. 'get the desktop that is in the bounds of the form (handy when using a
22. 'transparent Form or control in order to make a "viewfinder" for the capture...)
23. 'You can pass in any rectangle you want, this was so you can see how
24. 'it works...
25.
open in browser customize free license pdfcrowd.com
Happy coding! 
Attached Files
ScreenC apture.vb (5.9 KB, 8994 views)

Last edited by gigemboy; May 12th, 2006 at 01:35 PM.

  

 May 11th, 2006, 09:06
  #2
AM

maged Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Frenzied Member
this is very useful 
 

thank you
 
Join Date: Nov 02 rgds
Location: Egypt __________________
Posts: 1,040 Maged A. Reda
CEO of Softex Software House ­ Check Softex Superior Websites Here
  

 May 11th, 2006, 10:12
  #3
PM

gjon Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Hyperactive Member
Very neat, anyone make a windows app or a console app for this yet using this? 
 
I'd love to check it out.

 
Join Date: Nov 04
Location: Inescapable Void
Posts: 442

  

 May 12th, 2006, 01:32
open in browser customize free license pdfcrowd.com
 May 12th, 2006, 01:32
  #4
AM

gigemboy Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

"The" RedHeadedLefty
EZScreenCap in my sig was made using it, nothing fancy and I didn't spend a lot of time doing it. Just sort of a proof of
 
concept...

 
Join Date: Aug 05
Location: C ollege Station, TX
Preferred Nickname: Gig
C urrent Mood: Just Peachy
Turnons: String Manipulation
Posts: 4,487

  

 May 15th, 2006, 04:37
  #5
AM

lidds Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Addicted Member
gigemboy,
 
Join Date: May 06
Posts: 133 Thanks for the code it is exacually what I have been looking for, however I am having a really hard time trying to create
the code to allow the user to specify a region using mouse clicks. I noticed in your EZScreenCap you have this ability and
I was wondering if you would be able to help with the code that you used to acheive this.

Thanks inadvance

Simon
  

 May 18th, 2006, 03:55
  #6
PM

gigemboy Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

"The" RedHeadedLefty
Using mouse clicks?? You mean the "Viewfinder"? Its just a transparent panel on a form, and it gets the bounds of panel
 
when you capture it (after first hiding the form so it doesnt capture the form). The last code above describes it, although
in the example it uses the form bounds.

open in browser customize free license pdfcrowd.com


 
Join Date: Aug 05
Location: C ollege Station, TX
Preferred Nickname: Gig
C urrent Mood: Just Peachy
Turnons: String Manipulation
Posts: 4,487

  

 Aug 9th, 2006, 09:01
  #7
AM

mb2ai Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Lively Member
when i click on the attatchment, a html web page comes up and all the code is like a textfile, is it meant to be like this,
 
or is it an error.
Join Date: Jun 06
Posts: 64 Ideally id like to see how the application works, so I can use it for somthing.

MB
__________________
VS 2003
  

 Aug 13th, 2006, 06:06
  #8
PM

gigemboy Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

"The" RedHeadedLefty
Are you talking about the Class attachment? Its just a file.. if it doesn't ask you to save then your browser is set to do
 
something automatically with that file. Just right click the link and choose "save target as" or something. If you just see
the text, just save that file as a .VB file and add it to your project...

 
Join Date: Aug 05
Location: C ollege Station, TX
Preferred Nickname: Gig
C urrent Mood: Just Peachy
Turnons: String Manipulation
Posts: 4,487

  

 Aug 16th, 2006, 11:00
  #9
open in browser customize free license pdfcrowd.com
  #9
AM

mb2ai Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Lively Member
wow its wicked!
 
v good
Join Date: Jun 06
Posts: 64 __________________
VS 2003
  

 Sep 17th, 2006,
  #10
07:59 AM

steffanp Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Member
Hi i have been using your class but i have little problem. I have this loop that takes a sceenshot, and then analyzes it.
 
every time i use the class to take a screenshot, it filles my RAM with 6 extra megabytes (and it takes approx. 1 screenshot
Join Date: Aug 06
Posts: 35 every second. So after aboute 1 minute, it uses approx 700 MB RAM :S:S.. why?

VB C ode:

1. Dim SIR As New SteffansImageRecognizion()


2. Dim SC As New ScreenShot.ScreenCapture
3.
4. Dim ColorBuffer As System.Drawing.Color
5. Dim BitmapBuffer As System.Drawing.Bitmap
6. Dim ImageBuffer As System.Drawing.Image
7.
8. While (True)
9. BitmapBuffer = SC.CaptureDeskTopRectangle(New System.Drawing.Rectangle(0, 0, 0, 0), 1000
10.
11. ' Lots of code..
12.
13. End While

  

 Sep 17th, 2006, 02:12
  #11
PM

gigemboy Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

"The" RedHeadedLefty
Then I assume its something in your code that is not being disposed of properly, whatever you are doing in it. I don't
open in browser customize free license pdfcrowd.com
Then I assume its something in your code that is not being disposed of properly, whatever you are doing in it. I don't
 
believe its a problem in the class. I tested EZScreenCap, which uses the class, and after taking a few snapshots, the
memory increased by about 10­20 megabytes after taking a few quick snapshots in rapid succession, but after a short
time, it goes back down to about where it was before (a little higher just because of the extra graphics that it has to
display in the listview), after the garbage collector does its job and cleans up...
 
Join Date: Aug 05
Location: C ollege Station, TX
If you want to get help with your code, then feel free to post it, but please create a new thread in the regular VB.NET
Preferred Nickname: Gig section for it if you desire.
C urrent Mood: Just Peachy
Last edited by gigemboy; Sep 17th, 2006 at 02:17 PM.
Turnons: String Manipulation
Posts: 4,487

  

 Mar 15th, 2007, 12:59
  #12
PM

WoZ83 Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

New Member
Hi, I need to know how I can use your code on pocket pc using compact framework?!
 
Thanks a lot.
Join Date: Mar 07
Posts: 1

  

 Apr 16th, 2007, 01:54
  #13
PM

Giraffe Frenzy Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Addicted Member
gigemboy,
 
Join Date: Jun 06
Posts: 250 Do you know of a way to capture an image on a remote machine? Assuming that you have the correct permissions to do
so.

Last edited by Giraffe Frenzy; Apr 16th, 2007 at 02:03 PM.

  

 Jul 28th, 2007, 01:06
  #14
AM

RupinderSamra Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

New Member
this screen capture is great but i was wondering is it possible to take screen shots of the window when the window is
 
minimised?
Join Date: Jul 07

open in browser customize free license pdfcrowd.com


Posts: 2

  

 May 21st, 2008, 10:26
  #15
AM

zhshqzyc Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Hyperactive Member
I get three errors by using the example.
 
Declaration expected.
Join Date: Mar 08
Posts: 450
Imports System.Windows.Forms

Public Class Form1
Dim SC As New ScreenShot.ScreenCapture

'grabs image of object handle (in this case, the form)
Dim MyWindow As Image = SC.CaptureWindow(Me.handle)

'grabs image of entire desktop
Dim MyDesktop As Image = SC.CaptureScreen

'captures entire desktop straight to file

SC.CaptureScreenToFile("c:\desktop2.jpg", Imaging.ImageFormat.Jpeg)  'Here SC
'captures image of object handle (in this case, the form) straight to file

SC.CaptureWindowToFile(Me.Handle, "c:\window2.jpg", Imaging.ImageFormat.Jpeg)  'Here SC
'returns bitmap of region of desktop by passing in a rectangle
Dim MyBitMap As Bitmap = SC.CaptureDeskTopRectangle(New Rectangle(Me.Location.X, Me.Location.Y, _
Me.Width, Me.Height), Me.Width, Me.Height)

MyBitMap.Save("c:\desktopregion.jpg", Imaging.ImageFormat.Jpeg)  'Here MyBitMap
'above example gets rectangle of form that it is called in, you can get 
'desktop by calling me.hide before the actual function call in order to 
'get the desktop that is in the bounds of the form (handy when using a
'transparent Form or control in order to make a "viewfinder" for the capture...)
'You can pass in any rectangle you want, this was so you can see how
'it works... 
End Class

open in browser customize free license pdfcrowd.com


Anybody can help?

Thanks
  

 Jun 16th, 2008, 10:38
  #16
AM

chris128 Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Pro Grammar
very useful, thanks 
 
__________________
My free .NET Windows API library (Version 2.1 Released 29/07/2010)

Blog: cjwdev.wordpress.com
  Web: www.cjwdev.co.uk
Join Date: Jun 07
Location: England
Quote:
Posts: 7,397
Originally Posted by jmcilhinney 
Multi­threading is not fruit.

  

 Jan 21st, 2009,
  #17
09:07 AM

Bumbling Intern Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

New Member
I am currently having trouble with trying to implement the code.
 
Join Date: Jan 09 C ode:
Posts: 8 Imports System
Imports System.Diagnostics
Imports System.Drawing
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports DirectShowLib
Imports System.Runtime.InteropServices.ComTypes
Imports System.ComponentModel

Namespace Capture_The_Webcam

Public Class Form1


open in browser customize free license pdfcrowd.com
Inherits System.Windows.Forms.Form
'webcam code from http://www.codeproject.com/KB/audio-video/WebcamUsingDirectShowNET.aspx
'webcam feed is handled by picturebox1
Public Class ScreenCapture
Dim SC As New ScreenShot.ScreenCapture

'grabs image of object handle (in this case, the form)


Dim MyWindow As Image = SC.CaptureWindow(Capture2.Capture_The_Webcam.Form1.PictureBox1.Handle
'Dim SC As ScreenCapture.Screenshot

Public SRCCOPY As Integer = &HCC0020


' BitBlt dwRop parameter
Declare Function BitBlt Lib "gdi32.dll" ( _
ByVal hDestDC As IntPtr, _
ByVal x As Int32, _
ByVal y As Int32, _
ByVal nWidth As Int32, _
ByVal nHeight As Int32, _
ByVal hSrcDC As IntPtr, _
ByVal xSrc As Int32, _
ByVal ySrc As Int32, _
ByVal dwRop As Int32) As Int32
I keep getting the error that Screenshot.Screencapture is not defined. Any ideas?
THanks Declare Function CreateCompatibleBitmap Lib "gdi32.dll" ( _
ByVal hdc As IntPtr, _
   ByVal nWidth As Int32, _
ByVal nHeight As Int32) As IntPtr
 Jan 21st, 2009, 10:45
  #18
AM Declare Function CreateCompatibleDC Lib "gdi32.dll" ( _
ByVal hdc As IntPtr) As IntPtr
Bumbling Intern Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

New Member Declare Function DeleteDC Lib "gdi32.dll" ( _


Hi, ByVal hdc As IntPtr) As Int32
 
Join Date: Jan 09
Posts: 8 After some fiddling around, the problem was fixed by putting all the screen capture class code BEFORE the
Declare Function DeleteObject Lib "gdi32.dll" ( _
Capture_the_Webcam code.
ByVal hObject As IntPtr) As Int32

Declare Function SelectObject Lib "gdi32.dll" ( _


Much better now, great code it was very helpful. Thank you 
ByVal hdc As IntPtr, _
   ByVal hObject As IntPtr) As IntPtr
End Class 'GDI32
 Jan 23rd, 2009, '/ Helper class containing User32 API functions
  #19
09:43 PM

mcManiac Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls
Public Class User32
New Member
Hi guys, this code works but what i'm trying to do is get this code to take the picture and set it in a different directory ..
 
anyone got an answer?
<StructLayout(LayoutKind.Sequential)> _
Join Date: Jan 09
open in browser customize free license pdfcrowd.com
Join Date: Jan 09
Posts: 7
C ode:
Dim SC As New ScreenShot.ScreenCapture
Dim windowList As List(Of Game.WindowInfo) = Game.GetWindowList()
Dim screenshotname As String
screenshotname = grpInfo.Text & ".jpg"
SC.CaptureWindowToFile(DirectCast(windowList(lstGame.SelectedIndex), Game.WindowInfo).Handle, scr

  

 Mar 19th, 2009,
  #20
12:26 AM

BrailleSchool Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

PowerPoster Quote:
 
Join Date: Apr 05 Originally Posted by mcManiac 
Location: Debug.Print Hi guys, this code works but what i'm trying to do is get this code to take the picture and set it in a different directory ..
Posts: 3,802 anyone got an answer?

C ode:
Dim SC As New ScreenShot.ScreenCapture
Dim windowList As List(Of Game.WindowInfo) = Game.GetWindowList()
Dim screenshotname As String
screenshotname = grpInfo.Text & ".jpg"
SC.CaptureWindowToFile(DirectCast(windowList(lstGame.SelectedIndex), Game.WindowInfo).Handle, scree

where you have screenshotname, what about if you add the path you want to save the image to and then specify grpInfo.Text &
".jpg"
__________________
A+, e ­Biz+, i­Ne t+, MC DST, MC P, Ne twork +, Se curity+, A.A.S (Hons.)
Visual Basic .NET Vide o Tutorials | Login Form  using back e nd database  (.NET) | Use ful site  for se nding e m ail through .NET | Encrypt/De crypt data in SQ L
Se rve r 2005 using SQ L state m e nts | W riting Manage d Store d Proce dure s in SQ L Se rve r 2005 | FR EE .NET C ale ndar C ontrol | Use ful W inForm  C ontrols |
R e gular Ex pre ssion (R e x e x ) Library | Back up/R e store  SQ L Se rve r 2005 Database  using code | Ve rify SQ L Se rve r 2005 database  back up using SMO  | Back up
SQ L Se rve r 2005 database  using SMO  | R e store  SQ L Se rve r 2005 database  using SMO  | Use  Fx C op from  Microsoft to aid with code  optim ization

What I am using:
Microsoft Visual Basic Professional 2005 with .NET Framework 2.0 and Microsoft SQL Server 2005 or MySQL

open in browser customize free license pdfcrowd.com


  

 Apr 15th, 2009, 02:59
  #21
PM

SL1509 Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

New Member
Hi,
 
very good code, but i have a problem with my second monitor. On this screen the created screenshots are black.
Join Date: Apr 09
Posts: 1 Can anybody help?

Thanks a lot.
  

 Jun 19th, 2009,
  #22
07:42 PM

filthy_mcnasty Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

New Member
To the original poster: THANKS! This is cool stuff you've passed along and it saved me some time for sure.
 
Join Date: Jun 09
Posts: 1 To the last poster: I had a similar problem. I have lots of monitors and was getting nowhere trying to get a screenshot of
all of them at the same time.

GetDesktopWindow() API call will return the handle only for the primary video display, not the entire screen output....
booooo MS!!...... so this code will only take a screenshot of ONE monitor as is.

For the original poster: Instead of using User32.GetDesktopWindow() I found the REAL Window that represents the desktop
and modified your code so it will work across ALL screens.

C ode:
Dim base As IntPtr = User32.FindWindow("Progman", "Program Manager")
Dim b2 As IntPtr = User32.FindWindowEx(base, vbNullString, "SHELLDLL_DefView", vbNullString)
b2 = User32.FindWindowEx(b2, vbNullString, "SysListView32", vbNullString)

Return CaptureWindow(b2)

Before, the function was just Return CaptureWindow(User32.GetDesktopWindow())

also added:
<Runtime.InteropServices.DllImport("User32.dll")> _
open in browser customize free license pdfcrowd.com
Public Shared Function FindWindowEx(ByVal hwndParent As IntPtr, ByVal hwndChild As IntPtr, ByVal className As String,
ByVal caption As String) As IntPtr
End Function

<Runtime.InteropServices.DllImport("User32.dll")> _
Public Shared Function FindWindow(ByVal className As String, ByVal caption As String) As IntPtr
End Function

I'm pretty sure this behavior is consistent across all versions of Windows but I've only tested this in XP. 

Anyways, hope this saves someone else a headache, thanks again.
  

 Jul 23rd, 2009, 02:05
  #23
PM

NonProgrammer Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

New Member
Can somebody update the code to work with Microsoft Visual Basic 2008 for me? (And Post it for me too please!)
 
Join Date: Jul 09
Posts: 1

  

 Jul 28th, 2009, 06:41
  #24
AM

farooqaaa Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

New Member
I really want this class in C#. I've found one online but the "DesktopRectangle()" method isn't there.
 
Join Date: Jul 09
Posts: 9 Is it possible to get this class in C#?

Thanks
__________________
Farooq Azam ­ C# Tutorials, tips & tricks and more... 

Images & Videos 
  

 Sep 18th, 2009, 01:48
  #25
PM
open in browser customize free license pdfcrowd.com
PM

farooqaaa Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

New Member
A clone of this one is available for C# here:
 
http://www.farooqazam.net/screen­cap...ss­for­c­sharp
Join Date: Jul 09
Posts: 9

__________________
Farooq Azam ­ C# Tutorials, tips & tricks and more... 

Images & Videos 

  

 Nov 12th, 2009, 02:30
  #26
PM

Brian M. Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Lively Member
Very easy to use class, thanks alot! I spent hours trying to capture this control with no luck, until I added this class.
 
Here is an app I made that uses it to capture the control that is drawn on.

Lite Brite
__________________
  Brian M.'s Site
Join Date: Nov 06
Location: Moberly MO
Posts: 94

  

 Dec 23rd, 2009, 12:05
  #27
PM

youngaj Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

New Member Quote:
 
Join Date: Dec 09 Originally Posted by NonProgrammer 
Posts: 1 Can somebody update the code to work with Microsoft Visual Basic 2008 for me? (And Post it for me too please!)

open in browser customize free license pdfcrowd.com


I just stumbled on this code and it seems perfect, if I could only get it to work. I'm running VS 2008 as well and I'm
running into several problems.

Me.Handle is not recognized
Me.Location.X is not recognized
etc
Also I'm getting an error when I try to save the image to a file

I've attached my code behind
Attached Files
WindowTestPage.aspx.vb (2.6 KB, 88 views)

  

 Feb 24th, 2010, 03:43
  #28
AM

ramesh017  Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Lively Member
Hi 
 
Join Date: Jan 09
Posts: 67 im new to VB.NET... Can u pls tel me how to implement the code?? i mean form ? coz i have created a new form and
pasted the cod ein designer.. but its showing some error and the form was not loading:­(
  

 Feb 24th, 2010, 08:10
  #29
AM

Brian M. Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Lively Member
Hey ramesh, do you know what a class is? This is not code you can paste into a form, you have to make calls to the
 
class from your form code.

Classes

MSDN­vb classes
 
Join Date: Nov 06 Wikipedia­classes
Location: Moberly MO
Posts: 94 __________________
Brian M.'s Site

open in browser customize free license pdfcrowd.com


  

 Feb 24th, 2010, 11:56
  #30
PM

ramesh017 Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Lively Member
Cool... I need a piece of code which will capture screen shot of the form.. Can u help me to get it form this code!!
 
Join Date: Jan 09
Posts: 67

  

 Feb 25th, 2010,
  #31
01:06 PM

Brian M. Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Lively Member
First you must add the SCapture.vb class file to your project in the solution explorer. Then you have to make a button on
 
your form so you can have an event to capture the form picture. In the button's click event handler add this code:

C ode:
Dim filePath As String = My.Computer.FileSystem.SpecialDirectories.Desktop & "\myFormImage.png"
 
Join Date: Nov 06 Try
Location: Moberly MO Dim img As Image = SCapture.Control(Me.Handle, False)
Posts: 94 img.Save(filePath, Drawing.Imaging.ImageFormat.Png)
Catch ex As Exception
MessageBox.Show("Failed to capture the control!" _
& Environment.NewLine & ex.Message, "Capture Error!", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

Then when you click the button you put this code in, it should save a png image of your form to your desktop.
__________________
Brian M.'s Site
open in browser customize free license pdfcrowd.com
  

 Feb 26th, 2010, 01:57
  #32
AM

ramesh017 Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Lively Member
I did the same what u told.. But its showing soem error:­(
 
Join Date: Jan 09
Posts: 67 Also it is saying that Name 'screencapture' is not declared

  

 Feb 26th, 2010,
  #33
03:41 AM

ramesh017 Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Lively Member C ode:
 
Join Date: Jan 09
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Cli
Posts: 67
Dim filePath As String = "C:\Documents and Settings\175943\Desktop\mypicture.png"
Try
Dim img As Image = screencapture.Control(Me.Handle, False)

img.Save(filePath, Drawing.Imaging.ImageFormat.Png)
Catch ex As Exception
MessageBox.Show("Failed to capture the control!" _
& Environment.NewLine & ex.Message, "Capture Error!", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub

Private Sub Capture_window_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)


If Capture_window.Checked Then
Me.Opacity = 0.6
Else
Me.Opacity = 1

open in browser customize free license pdfcrowd.com


End If
If Capture_window.Checked And Doc_Button.Checked Then
Button2.Visible = False
Button1.Visible = False
Button3.Visible = True
ElseIf Capture_window.Checked And Img_Button.Checked Then
Button2.Visible = False
Button1.Visible = False
Button3.Visible = True
ElseIf Doc_Button.Checked = True Then
Button3.Visible = False
Button2.Visible = True
Button3.ForeColor = Color.Blue
End If

End Sub

Refer the code above.. 
Public Class screencapture

Public Function CaptureScreen() As Image


I got an error that control is not a member of 'mainwindow .screencapture'.
Return CaptureWindow(User32.GetDesktopWindow())
   End Function 'CaptureScreen

 Feb 26th, '/ Creates an Image object containing a screen shot of a specific window
2010, 12:35 Public Function CaptureWindow(ByVal handle As IntPtr) As Image   #34
Dim SRCCOPY As Integer = &HCC0020
PM
' get te hDC of the target window
Brian M. Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls
Dim hdcSrc As IntPtr = User32.GetWindowDC(handle)
' get the size
Lively Member
You must add the class file to your solution explorer. You can't add the class code to your form. You can either right click your
Dim windowRect As New User32.RECT
 
project in solution explorer or you can use the add item menu item. You pick add existing item and navigate to where your class file
User32.GetWindowRect(handle, windowRect)
Dim width As Integer = windowRect.right - windowRect.left
is stored then select it to add it to your project. Then remove the class code from your form code. See attached picture for an
example. Dim height As Integer = windowRect.bottom - windowRect.top
' create a device context we can copy to
Attached Images
Dim hdcDest As IntPtr = GDI32.CreateCompatibleDC(hdcSrc)

open in browser customize free license pdfcrowd.com


 
Join Date: Nov 06
Location: Moberly
MO
Posts: 94

__________________
Brian M.'s Site

open in browser customize free license pdfcrowd.com


  

 Mar 2nd, 2010,
  #35
12:26 AM

ramesh017 Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Lively Member
Hey Brian,
 
Join Date: Jan 09
Posts: 67 Thanks for your effort to teach me!! I have doen the same thing.. But its showing lot of errors!!

PFA

open in browser customize free license pdfcrowd.com


open in browser customize free license pdfcrowd.com
open in browser customize free license pdfcrowd.com
  

 Mar 2nd, 2010, 12:56
  #36
PM

Brian M. Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Lively Member
What version of Visual Studios are you using? This class is written for 2005.
 
__________________
Brian M.'s Site

 
Join Date: Nov 06
Location: Moberly MO
Posts: 94

  

 Mar 8th, 2010, 08:49
  #37
AM

sansharam  Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

New Member
Hi all
 
Join Date: Mar 10
Posts: 1 Can anybody help me??... 

Dear all 

I have an application which provides some data in datagrid ... by right click i can copy that and past that in to a text
file..... 

my quest is can i get this process done by vb.net code

Please help me

thanks in advance

sansharam

open in browser customize free license pdfcrowd.com


  

 Aug 10th, 2010, 09:51
  #38
PM

Dario  Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Junior Member
Using this screencapture class win winxp, and it does what i want.   very easy to use.
 

However on Windows 7 pc's (32 or 64 bit) - i get black image...

 
Any solutions for this win7 issue?
Join Date: Oct 06
Posts: 25
Just to add: the app i am making is SERVICE BASED & currently it works on WinXP, when installed on Win7, just black
image.

Last edited by Dario; Aug 10th, 2010 at 09:58 PM. Reason: Update..

  

 Aug 11th, 2010, 04:59
  #39
PM

03myersd Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Frenzied Member
Excellent class! So useful! Hard to believe .NET doesnt have this built in. Great solution though!
 
__________________
Join Date: Sep 06
Misc:
Location: Scotland
Talk ing To God.... | The  Last Q ue stion....
Posts: 1,044

  

 Aug 13th, 2010, 07:47
  #40
AM

Dario  Re: Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Junior Member
Quote:
 
Originally Posted by Dario 
Using this screencapture class win winxp, and it does what i want.   very easy to use.

 
Join Date: Oct 06
However on Windows 7 pc's (32 or 64 bit) ­ i get black image...
Posts: 25
Any solutions for this win7 issue?

open in browser customize free license pdfcrowd.com


Just to add: the app i am making is SERVICE BASED & currently it works on WinXP, when installed on Win7, just
black image.

Grrr been googling for 2 weeks on this issue, and all i can find is that some people have the same problem, and that
windows 7 gdi/win32 api has changed a great deal since introduction of VISTA and onwards, windows 7.

http://stackoverflow.com/questions/1...indows­service

Going crazy..

  

Page 1 of 2 1 2 >

« Previous Thread | Next Thread »
  VBForums  > VBForums C odeBank   > C odeBank ­ Visual Basic .NET
 Easy Screen Capture Class - Capture Screen, Desktop Region, Form, or Controls

Currently Active Users Viewing This Thread: 2 (1 members and 1 guests)
DanDx

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off Forum Jump

Forum Rules     C odeBank ­ Visual Basic .NET Go

All times are GMT ­5. The time now is 04:29 PM.

Contact Us - VB Forums - Archive - Top

open in browser customize free license pdfcrowd.com


MARKETPLACE

Curious about MS Desktop
Virtualization?
Le arn how C IO ’s can im prove  work space
fle x ibility while  se curing corporate  data.
W indows Ente rprise  Solutions

Software Developer Jobs at Microsoft
Sm art, C re ative  & Passionate  Pe ople . Join
O ur Tale nt C om m unity & Apply For Jobs.
Microsoft­C are e rs.com

ALM Software Solution – Try it live!
R e quire m e nts Manage m e nt, Proje ct
Planning, Im ple m e ntation Track ing & Q A
Te sting.
www.te che x ce l.com

Acceptable Use Policy  

 
The Netw ork for Technology Professionals

Search:   

About Internet.com 
Copyright 2011 QuinStreet Inc. All Rights Reserved.

Legal Notices, Licensing, Permissions, Privacy Policy. 
Advertise | New sletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
open in browser customize free license pdfcrowd.com
C opyright ©2000 ­ 2011, Jelsoft Enterprises Ltd.

open in browser customize free license pdfcrowd.com

You might also like