WebBrowser
This control can be used to display web pages. It has many useful options. You can use this Windows Forms control with C# code to create a kiosk-like browser.
To begin, drag a WebBrowser
to your Windows Form in Visual Studio, and add a Navigating event. The Load event on the form can be used to initialize WebBrowser
.
The control offers the Navigate()
method. This gives many options for changing the location of the currently viewed page.
WebBrowser
offers event handlers. These trigger when a page is being loaded and when the page is loaded.Form1_Load
handler.DocumentCompleted
, right-click on the WebBrowser
, select properties, and then click on the lightning bolt.using System; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // When the form loads, open this web page. webBrowser1.Navigate("http://www.dotnetperls.com/"); } private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e) { // Set text while the page has not yet loaded. this.Text = "Navigating"; } private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { // Better use the e parameter to get the url. // ... This makes the method more generic and reusable. this.Text = e.Url.ToString() + " loaded"; } } }
By default, you will get the context menu for when you right-click on the content area of the WebBrowser
. This can be disabled with a property.
IsWebBrowserContextMenuEnabled
property to False in the Properties window.DocumentCompleted
This event handler is often useful. The code you put in this handler is executed whenever the page you navigate to is finished loading.
The WebBrowser
control supports web browsing. Useful for providing a kiosk-style web browsing function, this control gives you the ability to handle local and remote web pages with ease.