How To Make A Simple Web Browser In C#

This is my first c# tutorial and its about making a web browser . this web browser doesnt have advanced controls this is just a simple one

lets begin making a simple web browser

1. open your visual c# 2008/2010

2.create a new project and name it whatever you want

3.edit your form properties like text and icon

4. now go to toolbox and grab web browser control inside the form



5. set the web browser in your form


6 . add 5 buttons

7. set the text of the buttons as below

button1 - back
button2 - forward
button3 - refresh
button4 - stop
button5 - go

8. now add a textbox

9. set everything like this


10. now double click your form and erase everything and paste this 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;

//Author : Mohamed Shimran
//Blog : http://www.ultimateprogrammingtutorials.blogspot.com

namespace simple_webbrowser
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            webBrowser1.GoForward();
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            textBox1.Text = e.Url.ToString();



        }

        private void button5_Click(object sender, EventArgs e)
        {

            webBrowser1.Navigate(textBox1.Text);
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            webBrowser1.GoBack();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            webBrowser1.Refresh();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            webBrowser1.Stop();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
11.debug and enjoy


you can make the form bigger and set the webbrowser control to the form and make the buttons bigger and add background pictures to them like for refreshing




 click the button below to download the source code



1 comments:

but pop up doesn't work coz popup windows is only available with IE

Reply

Post a Comment

Note: Only a member of this blog may post a comment.