locked
Take a screenshot of a web page.

    Question

  • Hello everyone. I am wondering if there is any way that I could take a screenshot of a web page that is displayed in a web browser and load it into a picturebox. Any and all help is appreciated.

    Thanks in advance, 
    Chris
    Saturday, October 18, 2008 5:11 PM

Answers

  • Pictureboxes have a variety of SizeModes, choose one you like.

    Saturday, October 18, 2008 9:17 PM

All replies

  • Do you want to take a screen shot during the run time?
    Saturday, October 18, 2008 5:18 PM
  • You can take a screenshot of whatever you wish using CopyFromScreen.  Use a graphics from the picturebox's image.

    Saturday, October 18, 2008 5:35 PM
  • I've tried this and it didn't work. However, I probably coded it wrong. If you could provide any source code that would be wonderful. Also, the web browser and the picturebox are on different forms if that has anything to do with it.
    Saturday, October 18, 2008 7:26 PM
  • Post your code and the error you got.  I don't know the error code for "didn't work".

    Saturday, October 18, 2008 7:38 PM
  • I would have posted the error, but there wasn't one. It simply didn't work. Like I said, I probably left something out or didn't do it right at all. Anyways, here's what I did.

            Dim g As Graphics = Form1.PictureBox1.CreateGraphics
            g.CopyFromScreen(webBrowser.Location, Form1.PictureBox1.Location, webBrowser.Size)

    Saturday, October 18, 2008 7:54 PM
  • Post the complete method or event containing the code you posted.

    Saturday, October 18, 2008 8:00 PM
  • Oh, sorry about that.

        Private Sub webBrowser_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles webBrowser.DocumentCompleted
            Me.Text = webBrowser.DocumentTitle
            AppManager.MainForm.cburl.Text = e.Url.ToString
            oDoc = webBrowser.Document
            Dim g As Graphics = Form1.PictureBox1.CreateGraphics
            g.CopyFromScreen(webBrowser.Location, Form1.PictureBox1.Location, webBrowser.Size)
        End Sub
    Saturday, October 18, 2008 8:05 PM
  • Replace the code you tried with this:

     

    Form1.PictureBox1.Image = New Bitmap(Me.WebBrowser.width, Me.webbrowser.Height)

    Using g As Graphics = Graphics.FromImage(Form1.PictureBox1.Image)

    g.CopyFromScreen(Me.WebBrowser.PointToScreen(Me.WebBrowser.Location), New Point(0, 0), Me.WebBrowser.Size)

    End Using

    Saturday, October 18, 2008 8:50 PM
  • I replaced my old code with the code you gave me. I'm just getting the picturebox with a plain white background. I'm wondering if this may be because the picturebox is significantly smaller than the web browser. If this is the problem then maybe getting the thumbnail of the image would be an easy solution?
    Saturday, October 18, 2008 9:01 PM
  • Pictureboxes have a variety of SizeModes, choose one you like.

    Saturday, October 18, 2008 9:17 PM
  • So easy I didn't even think of it! Thanks a ton for your help!
    Saturday, October 18, 2008 11:46 PM