Hi, in this tutorial I'm going to show you how to retreive an image of a webpage from the internet, and then display it in a picturebox:
First start Visual Basic (or visual studio if you have it) and go to File -> New Project -> Windows Forms Application
Name you project whatever you want. I called it 'WebCapture'.
You should now see a blank windows form infront of you. Resize it to whatever size you want. To the left of your form you should see the toolbox. On the toolbox, locate the 'PictureBox' Control, and drag it onto your form. You should now have a form with a picturebox on it.
Next, click on the picturebox, and to the right you should see the properties of the picturebox. Change the name of the picturebox to wbImage. Now find the 'SizeMode' property of the picturebox, and set it to 'Stretch'
Next, add a webbrowser control to your form and set the visible property to false. Change the webbrowser's name to 'WbMain'.
Now add a textbox and a button to your form. Name the textbox 'txtURL', and name the button 'btnNavigate'.
Now double click btnNavigate, and put this code into the button click event:
'Tell the webbrowser to navigate to whatever URL is in the textbox WbMain.Navigate(TxtUrl.text) 'Disable the navigate button for a second... btnNavigate.Enabled = False
Now double click your 'WbMain', and go to the DocumentCompleted event. Add this code:
'Declare two integers for the width and height of the webbrowser document Dim scrollWidth As Integer Dim scrollHeight As Integer 'Ser the integers to the size & height of the webbrowser document scrollHeight = wbMain.document.Body.ScrollRectangle.Height scrollWidth = wbMain.document.Body.ScrollRectangle.Width 'Resize the webbrowser to the size of the page wbMain.Size = New Size(scrollWidth, scrollHeight) 'Create a new bitmap the size of the webbrowser document Dim bm As New Bitmap(scrollWidth, scrollHeight) 'Capture the snapshot WbMain.DrawToBitmap(bm, New Rectangle(0, 0, bm.Width, bm.Height)) wbImage.Image = bm bm.Dispose() btnNavigate.Enabled = True
Now press F5 to begin debugging. Your form should show. Type a url into the textbox and click the button. A few seconds later (Depending on the speed of your internet connection) a snapshot of the page should appear in the picturebox.
So what did we actually do?
First we made the webbrowser navigate to the URL in the textbox, and then we made it take a snapshot of the document whenever it had finsished loadinf the page.