.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Working with web browser control in C#

Posted By:Abhisek Panda       Posted Date: November 25, 2009    Points: 25    Category: C#    URL: http://www.dotnetspark.com  

Working with web browser control in C#

        The System.Winsows.Forms.WebBrowser control is new to the .NET 2.0 and is a highly configurable mini web browser that may be embedded into any window form. This control defines a Url property that can be set to any valid Url, formally represented by the System.Uri type.

         First create a new Window form application in visual studio in C#. In the form add a WebBrowser control a label(lblUrl), a TextBox(txtUrl) to enter the Url and a button(btnGo) to perform the HTTP request. You can set different properties of WebBrowser control in the properties window. For now just change the Url property to"http://www.dotnetspark.com" so that when we run the application the webpage is displayed. Change the label's text property to "Enter URL". Now add the following code in the Click event handler of Go button.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;

namespace WebBrowser
public partial class WebBrowserUse : Form
private void btnGO_Click(object sender, EventArgs e)
// Set URL based on value in the TextBox control.
myWebBrowser.Url = new System.Uri(txtUrl.Text);

       Now run the application and you will see that the webbrowser control will display our DotNetSpark homepage. You can also enter other Url. But you have to specify the particular Url, i.e, "http://www.website.domain", otherwise it will not be able to show the page.
 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend