Thursday, January 7, 2010

How to create web browser using .NET

Open Visual Studio .NET, and click New Project. Then type in a name and location for your project.
Select the Visual Basic Windows application or Visual C# Windows application, depending on which language you wish to develop in.
When the form appears, right-click on the toolbox and select Customize Toolbox (Visual Studio .NET 2002) or Add/Remove Items (Visual Studio .NET 2003). Then select Microsoft Web Browser from the dialog box, and press OK.
Drag the Explorer icon onto the form, and then drag a button and textbox onto the form.
The next step is to set the properties of all the user interface elements. Right-click on the button and select the Properties option. You will see the Properties snap-in window appearing. Scroll up to the top of this window, and click on the property labeled (Name). Enter in the new name,
btnBrowse,Similarly, name the textbox tbURL and the Microsoft Web Browser control webBrowser.
If you double-click on the button, you will see a page of code already written for you. Find the reference to btnBrowse_Click and insert the following code:

VB.NET
Private Sub btnBrowse_Click(ByVal sender As _
System.Object, ByVal e As System.EventArgs) Handles _
btnBrowse.Click
webBrowser.Navigate(tbURL.Text)
End Sub
C#
private void btnBrowse_Click(object sender, System.EventArgs
e)
{
object notUsed = null;
webBrowser.Navigate(tbURL.Text,ref notUsed,ref notUsed, ref
notUsed, ref notUsed);
}