How do I create an image from my screen

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I want to create an image that looks exactly the same as the things I see in
my application.
I have an application in which you can create some controls, drag them
anywhere you like.
Now I want to export these controls to an image. The image should reflect
the position of the controls and the controls should look the same in the
picture as they do on the screen.

Is there anyway to do this in Visual Basic.Net 2003?

Thank you,
Steven
 
Steven said:
I want to create an image that looks exactly the same as the things I see
in
my application.
I have an application in which you can create some controls, drag them
anywhere you like.
Now I want to export these controls to an image. The image should reflect
the position of the controls and the controls should look the same in the
picture as they do on the screen.

<URL:http://www.google.com/[email protected]>

<URL:http://dotnet.mvps.org/dotnet/samples/windowsandforms/Screenshot.zip>
 
Hi,
Thank you for your reply.
I tried both methods as described in your links. The first method, drawing
each control separately worked, but with problems. All controls were drawn as
black rectangles.
Probably has to do with the fact that i use user defined controls.
The scond method works. After some editing I can take a screenshot of the
items in my application, as with CTR-PrintScreen
The next challenge I have to face is that my application uses scrollbars. So
I have to take multiple screenshots, after each screenshot scroll to a next
visible area, and afterwards glue these bitmaps together to form one big
bitmap.

I will puzzle some more to try to find this out. Thank you very much for
your help, I'm helped very much.

Steven
 
Here's code that I use to actually print the form image -- the technique
copies the screen image to a bitmap -- with modification it may work in
your case.

'***
<Conditional("DEBUG")> _
<System.Runtime.InteropServices.DllImport("gdi32.dll",
EntryPoint:="BitBlt", SetLastError:=True,
CharSet:=Runtime.InteropServices.CharSet.Auto,
CallingConvention:=Runtime.InteropServices.CallingConvention.Winapi)> _
Private Shared Function BitBlt( _
ByVal hdcDest As IntPtr, _
ByVal nXDest As Integer, _
ByVal nYDest As Integer, _
ByVal nWidth As Integer, _
ByVal nHeight As Integer, _
ByVal hdcSrc As IntPtr, _
ByVal nXSrc As Integer, _
ByVal nYSrc As Integer, _
ByVal dwRop As System.Int32) As Long

End Function

#If DEBUG Then
Private memoryimage As Bitmap
#End If

<Conditional("DEBUG")> _
Private Sub CaptureScreen()
Dim mygraphics As Graphics = Me.CreateGraphics()
Dim s As Size = Me.Size
memoryimage = New Bitmap(s.Width, s.Height, mygraphics)
Dim memoryGraphics As Graphics = Graphics.FromImage(memoryimage)
Dim dc1 As IntPtr = mygraphics.GetHdc
Dim dc2 As IntPtr = memoryGraphics.GetHdc
BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, _
Me.ClientRectangle.Height, dc1, 0, 0, 13369376)
mygraphics.ReleaseHdc(dc1)
memoryGraphics.ReleaseHdc(dc2)
End Sub

<Conditional("DEBUG")> _
Private Sub btnPrintForm_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPrintForm.Click
CaptureScreen()
PrintDocument1.Print()
End Sub

<Conditional("DEBUG")> _
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object,
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument1.PrintPage
e.Graphics.DrawImage(memoryimage, 0, 0)
End Sub
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top