Reputation: 43
I have 2 forms.
I need to screen shot the first form without making it on top of form 2 as well as without including content from form 2.
here is some what i am working with, which i am trying to fix.
Private Function TakeScreenShot(ByVal Control As Control) As Bitmap
Dim Screenshot As New Bitmap(Control.Width, Control.Height)
Control.DrawToBitmap(Screenshot, New Rectangle(0, 0, Control.Width, Control.Height))
Return Screenshot
End Function
This function is not working because Control.drawtoBitmap is not setting the value of IMG.
IMG is blank and being returned as a plain white image.
The calling of this function is this
TakeScreenShot(form1.webbrowser1).Save("c:\Screenshot.png",
System.Drawing.Imaging.ImageFormat.Png)
All help would be appreciated.
Upvotes: 4
Views: 16020
Reputation: 483
Replace your TakeScreenShot
function with this:
Private Function TakeScreenShot(ByVal Control As Control) As Bitmap
Dim tmpImg As New Bitmap(Control.Width, Control.Height)
Using g As Graphics = Graphics.FromImage(tmpImg)
g.CopyFromScreen(Control.PointToScreen(New Point(0, 0)), New Point(0, 0), New Size(Control.Width, Control.Height))
End Using
Return tmpImg
End Function
This should work, however if for some reason it doesn't the problem might be the transparent form on top.
You can call it in excactly the same way.
Good luck :)
Upvotes: 14