How do I take a screenshot in VB.net 2005

  • Thread starter Thread starter Bob
  • Start date Start date
B

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
 
Bob said:
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)
 
Back
Top