vb.net winform screenshot save to image even if workstation is locked?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have this great code below that does a screen capture of my winform but found that it fails if the workstation is locked.

<pre class="prettyprint lang-vb Private Sub Btn_Image_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Image.Click

Me.WindowState = FormWindowState.Normal
Me.TopMost = True
Me.Activate()
Me.Refresh()
Dim bmpScreenshot As Bitmap = New Bitmap(Width, Height, PixelFormat.Format32bppArgb)
Create a graphics object from the bitmap
Dim gfxScreenshot As Graphics = Graphics.FromImage(bmpScreenshot)
Take a screenshot of the entire Form1
gfxScreenshot.CopyFromScreen(Me.Location.X, Me.Location.Y, 0, 0, Me.Size, CopyPixelOperation.SourceCopy)
Save the screenshot
bmpScreenshot.Save("image.jpg", ImageFormat.Jpeg)

End Sub[/code]
I get the below Win32Exception error if the workstation is locked, I need help by fixing the above code or a new method. any help is greatly appreciated.

<img alt="" src="http://social.msdn.microsoft.com/Forums/getfile/217946
<br/>

View the full article
 
Back
Top