# VBForums CodeBank > CodeBank - Visual Basic .NET >  screen capture

## .paul.

here's my screen capture application

*edit:* see updated version - post #14

----------


## manhit45

Thanks for example. please guid me about it.

how can i capture .

----------


## JugglingReferee

> Thanks for example. please guid me about it.
> 
> how can i capture .


You're kidding, right?

----------


## .paul.

press your PrtScrn button. 

for capturing selected rectangle, press your PrtScrn button, select an area, then press your PrtScrn button again.

----------


## ForumAccount

1) Doesn't work properly with dual monitors - only captures primary monitor, same with rectangle selection.
2) There are two shared member warnings: lines 143, 145
3) You should delete the bin/obj folders...

Other then that, it works good.

----------


## .paul.

> 1) Doesn't work properly with dual monitors - only captures primary monitor, same with rectangle selection.
> 2) There are two shared member warnings: lines 143, 145
> 3) You should delete the bin/obj folders...
> 
> Other then that, it works good.


1/ i can't change that. no way for me to test it.
2/ i don't get a warning on those lines
3/ i deleted the binaries

Other than that, thanks :Big Grin:

----------


## ForumAccount

Are warnings suppressed in your projects?

----------


## .paul.

no. i just turned all warnings + option strict on. got a lot of warnings, but not that. it must be something to do with dual screens

----------


## ForumAccount

```
#Region "     notifyicon"

    Private Sub ni1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ni1.MouseDoubleClick
        Me.Show()
        If e.Button = MouseButtons.Left And Me.WindowState = FormWindowState.Minimized Then
            Me.WindowState = FormWindowState.Normal
        ElseIf e.Button = MouseButtons.Left And Me.WindowState = FormWindowState.Normal Then
            Me.Activate()
        End If
    End Sub

#End Region
```

----------


## .paul.

try changing them to 
vb Code:
System.Windows.Forms.MouseButtons.Left

shouldn't need to though. the reference is there.

----------


## austinjf785

It won't work with 2010 Express

----------


## formlesstree4

> It won't work with 2010 Express


Not much help there. What's wrong, we need the error information (more specifically .paul. does)

----------


## gep13

Hey,

I didn't think that Visual Studio 2010 Express had been released.

Am I missing something?

Gary

----------


## .paul.

heres an updated version. i've upgraded it to VB2008, + added support for dual monitors. 
it now captures:
1/ (either) whole screen, depending where the cursor is.
2/ the active window, whichever screen its displayed on.
3/ a selected rectangle from either screen again depending where the cursor is.




> Originally Posted by austinjf785  
> It won't work with 2010 Express





> Originally Posted by gep13
> I didn't think that Visual Studio 2010 Express had been released.


neither did i

----------


## ForumAccount

It's not, he must mean the Beta.

----------


## gep13

Hey,

I am running the Beta 1 of Visual Studio 2010, but I didn't think there was a Beta of the Express Editions, if so, where is the download, would be interesting to have a look!

Good work by the way Paul.

Gary

----------


## pimvdb

I like your project, especially how you've made the rectangle selection work.

However, to be honest the selection is drawn quite slowly. It might be my computer that is the problem, but invalidating the form every time the cursor moves doesn't really give a decent speed to an application.
Another tip, you should save screenshots in .png format, not in .jpg. The quality of .jpg is very bad for screenshots whereas there's no quality lose in the .png format.

Other than that it's been very helpful for me. Thanks.

----------


## gep13

Hey,

This is an open forum, and I am sure .paul. wouldn't find if you took his code and submitted your own changes/improvements.

Gary

----------


## .paul.

> Hey,
> 
> This is an open forum, and I am sure .paul. wouldn't find if you took his code and submitted your own changes/improvements.
> 
> Gary


no i probably wouldn't find :Big Grin:  + i wouldn't mind either. if you can improve it, go for it.





> I like your project, especially how you've made the rectangle selection work.
> 
> However, to be honest the selection is drawn quite slowly. It might be my computer that is the problem, but invalidating the form every time the cursor moves doesn't really give a decent speed to an application.
> Another tip, you should save screenshots in .png format, not in .jpg. The quality of .jpg is very bad for screenshots whereas there's no quality lose in the .png format.
> 
> Other than that it's been very helpful for me. Thanks.


jpeg provides good enough quality for me. the invalidating is necessary to redraw the selection rectangle, + it works ok on my pc, but maybe not on an older or less powerful pc

----------


## gep13

> no i probably wouldn't find + i wouldn't mind either. if you can improve it, go for it.


Doh!!  Damn my bad typing  :Smilie:

----------


## pimvdb

Actually I already tried to enhance the speed, but with no luck. Removing the invalidating part even didn't matter, it was painted well without but didn't speed up the whole. My computer sure isn't the best out there but I'll keep trying  :Smilie:

----------


## Emcrank

doesn't work, i get Object reference not set to an instance of an object.
at this part.


```
        regShell = regKey.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", False)
        If LCase(regShell.GetValue("screen capture").ToString) = Application.ExecutablePath.ToLower Then    <--- this line
            RunToolStripMenuItem.Checked = True
        End If
```

----------


## gep13

Which part of that code actually throws the error?  Have you tried stepping into it with the debugger?

Gary

----------


## Emcrank

I pointed to it, where it says "this line" thats where it gets highlighted

----------


## gep13

Oops, I never scrolled right, my bad...

In your code, you should get that this:



```
regShell.GetValue("screen capture")
```

Isn't returning null/Nothing, before accessing a member of that variable.  Are you sure you have a reg key with that name set up?

Gary

----------


## Emcrank

i downloaded the project did nothing tryed to debug it and got error of what i showed you, so if it was set up in the source then yes i did have it set up.

----------


## gep13

Interesting.

I think this might be a slight glitch with the problem, that wasn't highlighted in initial testing, as that registry key would have already been in place.

Try changing that section of the code to something like the following:



```
        regShell = regKey.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", False)
        If Not regShell.GetValue("screen capture") Is Nothing Then
            If LCase(regShell.GetValue("screen capture").ToString) Is Application.ExecutablePath.ToLower Then
                RunToolStripMenuItem.Checked = True
            End If
        End If
```

That should get it to work.

Gary

----------


## Emcrank

ok now when i click the green arrow(Debug) it starts because it dims out but no forms or anything show up

----------


## .paul.

it's minimized to an icon in your system tray

----------


## gep13

double click the system tray icon.

----------


## .paul.

as gary said, double click the system tray icon to restore the options form, or press the prtscr button to capture

----------


## Emcrank

oh ok sorry i didn't realise :/

----------


## Emcrank

if i dont click Launch in paint? then is form2 ment to appear with the picture on? because mine doesn't

----------


## .paul.

no. it saves the image to a folder called images in the app's bin/debug folder

----------


## jordy12345

Hello,

Thanks for the source, its awesome!
But I need to know one thing.
If you click prnt screen when you have capture selected rectangle on, you have to click prnt screen again to actually save the image.
Is there a way to not have to press prnt screen again, so it just saves it whenever you drawn your first rectangle?

Also when im building the project and I try to run the application it gives me this error, whats wrong?



Thanks,
Jordy

----------


## .paul.

> Hello,
> 
> Thanks for the source, its awesome!
> But I need to know one thing.
> If you click prnt screen when you have capture selected rectangle on, you have to click prnt screen again to actually save the image.
> Is there a way to not have to press prnt screen again, so it just saves it whenever you drawn your first rectangle?
> 
> Also when im building the project and I try to run the application it gives me this error, whats wrong?
> 
> ...


you could use the mouseup event instead of a 2nd PRTSCR
as for the error msg, can you translate that into english?

----------


## jordy12345

> you could use the mouseup event instead of a 2nd PRTSCR
> as for the error msg, can you translate that into english?


If you wanna see the error yourself, then download the zip here

screen capture_1_0_0_0.zip

If you dont want to do that, here is the code translated in google translator.



```
There is an unhandled exception occurred in the application. If you click Continue, this error is ignored and the application. If you click Quit, the application is immediately closed.

There is a general error occurred in GDI +.
```



```
See the end of this message for details on invoking
JIT (Just In Time) debugging instead of this dialog box.

************** Exception Text **************
System.Runtime.InteropServices.ExternalException (0x80004005): There is a general error occurred in GDI +.
***at System.Drawing.Image.Save (String filename, Image Codec encoder, Encoder Parameters encoderParams)
***screen_capture.Form1.WndProc (Message & m)
***at System.Windows.Forms.NativeWindow.Callback (IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)


************** Loaded Assemblies **************
mscorlib
****Assembly Version: 4.0.0.0
****Win32 Version: 4.0.30319.18034 built by: FX45RTMGDR
****Codebase: file :/ / / C :/ Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
----------------------------------------
screen capture
****Assembly Version: 1.0.0.0
****Win32 version: 1.0.0.0
****Codebase:
----------------------------------------
Microsoft.VisualBasic
****Assembly Version: 10.0.0.0
****Win32 version: 11.0.50709.17929 built by FX45RTMREL
****Codebase:
----------------------------------------
System
****Assembly Version: 4.0.0.0
****Win32 Version: 4.0.30319.18034 built by: FX45RTMGDR
****Codebase: file :/ / / C :/ WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Core
****Assembly Version: 4.0.0.0
****Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
****Codebase:
----------------------------------------
System.Windows.Forms
****Assembly Version: 4.0.0.0
****Win32 Version: 4.0.30319.18036 built by: FX45RTMGDR
****Codebase:
----------------------------------------
System.Drawing
****Assembly Version: 4.0.0.0
****Win32 Version: 4.0.30319.18021 built by: FX45RTMGDR
****Codebase:
----------------------------------------
System.Runtime.Remoting
****Assembly Version: 4.0.0.0
****Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
****Codebase:
----------------------------------------
System.Configuration
****Assembly Version: 4.0.0.0
****Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
****Codebase:
----------------------------------------
System.Xml
****Assembly Version: 4.0.0.0
****Win32 Version: 4.0.30319.18034 built by: FX45RTMGDR
****Codebase:
----------------------------------------
Accessibility
****Assembly Version: 4.0.0.0
****Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
****Codebase:
----------------------------------------
System.Drawing.resources
****Assembly Version: 4.0.0.0
****Win32 Version: 4.0.30319.1 built by: RTMRel
****Codebase:
----------------------------------------
System.Windows.Forms.resources
****Assembly Version: 4.0.0.0
****Win32 Version: 4.0.30319.1 built by: RTMRel
****Codebase:
----------------------------------------
mscorlib.resources
****Assembly Version: 4.0.0.0
****Win32 Version: 4.0.30319.1 (RTMRel.030319 0100)
****Codebase:
----------------------------------------

************** JIT Debugging **************
If you want to enable JIT debugging in the configuration file for this
application or computer (machine.config) the value
jitDebugging are set in the system.windows.forms section.
The application must also be compiled with debugging
was enabled.

For example:

<configuration>
****<system.windows.forms jitDebugging="true" Deal
</ Configuration>

When JIT debugging is enabled, any unhandled exception
sent to the JIT debugger registered on the computer
and are not handled by this dialog.
```

----------


## .paul.

@jordy
i think you'll find the error is due to filesystem security not allowing file saving in that location.
try changing the save to folder...

----------


## jordy12345

> @jordy
> i think you'll find the error is due to filesystem security not allowing file saving in that location.
> try changing the save to folder...


Thanks for your reply, the problem was that it couldn't  save the picture because there was no images directory in the folder.
I thought that it would create the folder automaticly, thanks.

----------


## IT researcher

In windows 8 when i press print screen button i am getting error as shown below(tested in about 3 windows 8 pc)

----------


## .paul.

I'm not sure what's happened there.
There's no way for me to try to recreate the error, as I don't have win 8.

----------


## jordy12345

Is it possible for you to also release a c# version of this?

----------


## .paul.

I have no plans to release a c# version.
You could convert it yourself. There are online converters at:

http://www.developerfusion.com/tools.../vb-to-csharp/

http://converter.telerik.com/

----------

