ARTICLE

Windows Forms WebBrowser Control

Posted by Mahesh Chand Articles | Visual Studio 2010 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.
Reader Level:
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 ;).

Login to add your contents and source code to this article
post comment
     

hi,The project is working very well with me, but an error appears when trying to open html page contains embedded ActiveX controls. Please give me your advise to overcome this problem.The error message that appear is : " The program is stopped working A problem caused the program to stop working correctly Windows will close the program and notify you if a solution is available"When debug The error message that appear is : {"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."}

Posted by Mohamed Hanafy Feb 21, 2013

hi

Posted by Bipin Dalbhide Jul 30, 2012

Hi Mahesh, I am working on a small c# application that uses an embedded webbrowser in a windows form. I want to use the print option from the webbrowser toolbar. The print method of the browser does a terrible job on the report, but the toolbar print option gives me what I need. Can you tell me how to access this functionality? Thanks.

Posted by Mark Kasun Nov 10, 2011

sir, this is good article but i am a fresher and want to ristrict or bane an url for parrental control in my project.

Posted by dhirendra jaiswal Nov 04, 2011

vai tore thanks. ei jinis life e dekhar luck hoy ni

Posted by MIRZA NURNOBI Sep 05, 2010
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter