Web Browser Control In Windows Form

Here I am explaining the web browser control in windows form. This control is just like a browser, it will open any web site in it.

So here are the steps for displaying web browser control.

  • Open a new windows project.
  • Take a textbox,web browser control and a button on the form.
  • Arrange the form as shown in the following figure.

Adjust the height and width of the web browser control so that it could clearly show a web site.

Under button click,  write the following code to display the url in the web browser control.

  1. private void button1_Click(object sender, EventArgs e)   
  2. {  
  3.     if (textBox1.Text != null)   
  4.     {  
  5.         webBrowser1.Url = new System.Uri(textBox1.Text, System.UriKind.Absolute);  
  6.     }   
  7.     else   
  8.     {  
  9.         MessageBox.Show("Please Enter a URL");  
  10.     }  
  11. }
Now run the application with typing the c# Csharp corner url and click on Browse button.

Now click google.com in the textbox.

In this way the web browser works and we can open any URL in it.

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now