Reader Level:

Display a Web Page in a Windows Forms

By Ashish Singhal on Jan 31, 2006
In this article, we will see how we can display a web page on Windows Forms.

Here in this article, we will see how we can open a web page in a Windows Forms.

To open web page we need to add webbrowser control on the windows form.

Go to toolbox and right click on that, you will see text "add/remove items",  click on that will open a dialog having .NET and Com components, click on com tab and select Microsoft web browser, after selection you will see control in toolbox then you can use similar as we use other controls, simply drag and drop on page.


Fig. 1

using System;
using System.Windows.Forms;
namespace OpenBrowser

          public class WebPage : System.Windows.Forms.Form



                    private AxSHDocVw.AxWebBrowser axWebBrowser1;

                    private System.Windows.Forms.Button browseButton;


                    public WebPage ()





                    private void InitializeComponent()


                             System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(WebPage));

                             this.browseButton = new System.Windows.Forms.Button();

                             this.axWebBrowser1 = new AxSHDocVw.AxWebBrowser();





                             // browseButton



                             this.browseButton.Location = new System.Drawing.Point(8, 8);

                             this.browseButton.Name = "browseButton";

                             this.browseButton.TabIndex = 1;

                             this.browseButton.Text = "Browse";

                             this.browseButton.Click += new System.EventHandler(this.browseButton_Click);



                             // axWebBrowser1



                             this.axWebBrowser1.Enabled = true;

                             this.axWebBrowser1.Location = new System.Drawing.Point(10, 40);

                             this.axWebBrowser1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser1.OcxState")));

                             this.axWebBrowser1.Size = new System.Drawing.Size(980, 808);

                             this.axWebBrowser1.TabIndex = 6;



                             // WebPage



                             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

                             this.ClientSize = new System.Drawing.Size(292, 266);



                             this.Name = "WebPage";

                             this.WindowState = System.Windows.Forms.FormWindowState.Maximized;





                    /// <summary>

                    /// The main entry point for the application.

                    /// </summary>



                    static void Main()


                             Application.Run(new WebPage ());


                    private void browseButton_Click(object sender, System.EventArgs e)


                             // Use Following code with version 2.0

                             // Use Following code with version 1.1

                             //System.Object nullObject = 0;
                             //string str = "";
                             //System.Object nullObjStr = str;
                             //Cursor.Current = Cursors.WaitCursor;
                             //axWebBrowser1.Navigate(@"",ref nullObject, ref
                             nullObjStr, ref nullObjStr, ref nullObjStr);
                             //Cursor.Current = Cursors.Default;




Ashish Singhal
Ashish Singhal

Ashish has been working as a software engineer since 2002. He has written articles for C# Corner . He specializes in the implementation of client/server, database, graphics and/or Internet-based systems using Visual Stud... Read more