Reader Level:
Articles

Windows Forms WebBrowser Control

By Mahesh Chand on November 10, 2005
Windows Forms 1.0 lacked a Web Browser control. The work around was to use IE ActiveX control using COM Interop. Now Windows Forms 2.0 provides a Web Browser control, which is a managed wrapper of IE ActiveX control.
  • 0
  • 0
  • 70558
Download Files:
 

In year 2001, I wrote an article on how to use IE Browser ActiveX control in your Windows Forms applications using COM Interop.

Now Windows Forms 2.0 (ships with Visual Studio 2005) comes with a Windows Forms Web Browser control, which is again is a wrapper of IE ActiveX control. This control is available in Visual Studio 2005 Toolbox. See Figure 1.

Figure 1. WebBrowser control in Toolbox

To add this control to your application, just drag and drop on the form. Now I add a TextBox and a Button control to the Form, change their Name and Text properties, and write the following code on the button click event handler.

private void BrowseBtn_Click(object sender, EventArgs e)
{
webBrowser1.Url = UrlTextBox.Text;
}

Now run the application, type a URL in the TextBox and click the button. The output is Figure 2.

Figure 2. Using WebBrowser control

WebBrowser control is represented by System.Windows.Forms.WebBrowser class.

In this control, you can set some properties such as IsWebWebBrowserContextMenuEnabled, SecurityLevel, and WebBrowserShortcutEnabled. See Figure 3.

Figure 3. WebBrowser control properties.

Personally, I am really not fond about this control. What I would really like to see in this control was to have property to show URL TextBox and button built-in the control itself. So as a programmer, if I wanted the URL TextBox to be displayed, I would simply set the property.

Other features I would like see in this control could be all the features IE and other browsers provide. I guess Microsoft always leaves something for us programmers to do ;).

Mahesh Chand

Mahesh Chand is founder of C# Corner. C# Corner founded in 1999 is a FREE member contributions based open platform for developers to solve problems, learn new technology and hang out.  Mahesh has been awar... Read more

COMMENT USING

Trending up