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

Introduction

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
  • button3 = new file button

Code

using System;  
using System.Collections.Generic;  
using System.ComponentModel;  
using System.Data;  
using System.Drawing;  
using System.Linq;  
using System.Text;  
using System.Windows.Forms;  
namespace BeHe_Browser   
{  
    public partial class Form1: Form   
    {  
        public Form1()   
        {  
            InitializeComponent();  
            webBrowser1.Navigate("www.google.com");  
        }  
        private void button3_Click(object sender, EventArgs e)   
        {  
            TabPage tabpage = new TabPage();  
            tabpage.Text = "New File";  
            tabControl1.Controls.Add(tabpage);  
            WebBrowser webbrowser = new WebBrowser();  
            webbrowser.Parent = tabpage;  
            webbrowser.Dock = DockStyle.Fill;  
            webbrowser.Navigate("www.google.com");  
        }  
        private void button1_Click(object sender, EventArgs e)  
        {  
            webBrowser1.Navigate(textBox1.Text);  
        }  
        private void button2_Click(object sender, EventArgs e)   
        {  
            if (webBrowser1.CanGoBack)   
            {  
                webBrowser1.GoBack();  
            } else {  
                MessageBox.Show("You cannot go back");  
            }  
        }  
        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)   
        {  
            textBox1.Text = webBrowser1.Url.ToString();  
        }  
    }  
}  


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.


Similar Articles