Home All Groups Group Topic Archive Search About

How do I take a screenshot in VB.net 2005

Author
5 May 2006 4:09 PM
Bob
Dim objRectangle As Rectangle = Screen.PrimaryScreen.Bounds

Dim objBitmap As New Bitmap(objRectangle.Right, objRectangle.Bottom)

Dim objGraphics As Graphics

objGraphics = objGraphics.FromImage(objBitmap)

Last line wont evaluate in Vs 2005, worked OK in 2003

Thanks for help

Bob

Author
5 May 2006 5:09 PM
Larry Lard
Bob wrote:
> Dim objGraphics As Graphics
>
> objGraphics = objGraphics.FromImage(objBitmap)
>
> Last line wont evaluate in Vs 2005, worked OK in 2003
(it helps to say what error message you get - I am assuming you are
getting "Access of shared member, constant member, enum member or
nested type through an instance; qualifying expression will not be
evaluated.")


FromImage is a Shared method of Graphics - that is it 'belongs' to the
class, not to any particular instance. Pre-VB2005, this (technically
incorrect) syntax of invoking class methods through an instance was
allowed without comment. In VB2005, it is by default a warning. The
correct syntax is

objGraphics = Graphics.FromImage(objBitmap)


--
Larry Lard
Replies to group please
Author
5 May 2006 7:02 PM
Herfried K. Wagner [MVP]
"Bob" <bduf***@sgiims.com> schrieb:
> [Creating a screenshot in .NET 2.0]

Check out 'Graphics.CopyFromScreen' (.NET 2.0).

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
6 May 2006 10:25 AM
Bob
Thanks to you both!
Bob
Show quoteHide quote
"Bob" <bduf***@sgiims.com> wrote in message
news:exH$74FcGHA.3840@TK2MSFTNGP04.phx.gbl...
> Dim objRectangle As Rectangle = Screen.PrimaryScreen.Bounds
>
> Dim objBitmap As New Bitmap(objRectangle.Right, objRectangle.Bottom)
>
> Dim objGraphics As Graphics
>
> objGraphics = objGraphics.FromImage(objBitmap)
>
> Last line wont evaluate in Vs 2005, worked OK in 2003
>
> Thanks for help
>
> Bob
>
>
>
>
>
>