How to Create a Simple Multi-Tabbed Web Browser in C#

Hi guys,

This article shows how to create a simple multi-tabbed web browser in C#. I'll call it BeHe Browser.

First, we will create a Windows Forms form and add a tab control to it. In the tab control I will add a web browser. I will also add three buttons and a TextBox.

OK, the design part is completed, now let's write the code. I will let the names of the control as default (like button1, button2 and so on).

In my case:

button1 = go button
button2 = go back button
and button3 = new file button;

This is the code:
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9. namespace BeHe_Browser   
  10. {  
  11.     public partial class Form1: Form   
  12.     {  
  13.         public Form1()   
  14.         {  
  15.             InitializeComponent();  
  16.             webBrowser1.Navigate("www.google.com");  
  17.         }  
  18.         private void button3_Click(object sender, EventArgs e)   
  19.         {  
  20.             TabPage tabpage = new TabPage();  
  21.             tabpage.Text = "New File";  
  22.             tabControl1.Controls.Add(tabpage);  
  23.             WebBrowser webbrowser = new WebBrowser();  
  24.             webbrowser.Parent = tabpage;  
  25.             webbrowser.Dock = DockStyle.Fill;  
  26.             webbrowser.Navigate("www.google.com");  
  27.         }  
  28.         private void button1_Click(object sender, EventArgs e)  
  29.         {  
  30.             webBrowser1.Navigate(textBox1.Text);  
  31.         }  
  32.         private void button2_Click(object sender, EventArgs e)   
  33.         {  
  34.             if (webBrowser1.CanGoBack)   
  35.             {  
  36.                 webBrowser1.GoBack();  
  37.             } else {  
  38.                 MessageBox.Show("You cannot go back");  
  39.             }  
  40.         }  
  41.         private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)   
  42.         {  
  43.             textBox1.Text = webBrowser1.Url.ToString();  
  44.         }  
  45.     }  
  46. }  





 
Now it's finished. Remember that this is for beginners and has nothing difficult to understand. It still doesen't have the one feature for "go" and "back" buttons, it only works for the first web browser(webbrowser1), they will not work for the webbrowsers in the new opened files. Doing this can be a little bit tricky.

Enjoy the web browser you've created.

Thanks guys.

Up Next
    Ebook Download
    View all
    Learn
    View all