1

All I want to do is to be able to take a screenshot of a control (in this instance a webbrowser) while the form is hidden-minimized or the webbrowser is on the background.

I want to take it as a bitmap using a timer, every time timer ticks I want to take an image-bitmap of that control. I'm abled to do it when the control is on the top.

Private Function Screenshot(x1 as integer,x2 as integer,y1 as integer,y2 as integer) As Bitmap
    Dim bounds As Rectangle
    Dim screenshot As System.Drawing.Bitmap
    Dim graph As Graphics
    bounds = Screen.PrimaryScreen.Bounds
    screenshot = New System.Drawing.Bitmap(x1 - x2, y1- y2, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
    graph = Graphics.FromImage(screenshot)
    graph.CopyFromScreen(x1, y1, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
    Return screenshot
End Function
Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
frtuc
  • 11
  • 3
  • 3
    Show the code you are using to get this screenshot when on top – Matt Wilko Aug 22 '14 at 15:30
  • Bear in mind browsers often don't bother rendering content at all when they're in the background, so trying to capture that content might be a wasted effort anyway. – Psychemaster Aug 22 '14 at 15:33
  • 2
    there is a `Control.DrawToBitmap` method but Windows doesnt update anything the user can't see (as when behind something or minimized). – Ňɏssa Pøngjǣrdenlarp Aug 22 '14 at 15:36
  • I apparently can't put my webbrowser on top, it needs to be on the back. – frtuc Aug 22 '14 at 15:45
  • DrawToBitmap should work, even when the window is at the back of the Z order. – Cody Gray - on strike Aug 22 '14 at 15:59
  • thanks for idea but I can't get control.drawtobitmap working even if the control is on top, it gives a blank bitmap, any idea why(I'll try but it seems that it doesn't work)? – frtuc Aug 22 '14 at 16:07
  • DrawToBitmap() does not work for a few controls in the toolbox, the kind that have non-standard rendering behavior. WebBrowser is one of them. IHTMLElementRender::DrawToDC() doesn't work anymore either, put to pasture by GPU acceleration and competition with Chrome. You can only have a shot at it with the code you posted, having the browser window in the foreground is a rock-hard requirement. – Hans Passant Aug 22 '14 at 16:15
  • What about WM_PRINT? I couldn't find any examples anyway. – frtuc Aug 22 '14 at 16:49

0 Answers0