Jump to content

Creating A Simple Web Browser.

- - - - -

  • Please log in to reply
44 replies to this topic

#1
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Today I'm going to show you how to make a simple web browser with all the basic features like home back forward refresh ect...

So to get started you with our web browser make a new windows forms application and name it MyWebBrowser or whatever you want.

OK now add a new Tool Strip to the top of the form(Tool Strip can be found in the tool box in the menu and toolbars tab) OK now add a Web Browser to the center of the form and size it to the size you want.(Web Browser is at the very bottom of the common controls tab in the tool box)

OK now we need some buttons for our form so click on the Tool Strip you placed on the top of the form and there should be a little blue box that pops up left click it and a picture button will pop up do this intel you have 5 picture buttons. Now click the little arrow on the Tool Strip add thing and select text box then add one more picture button.

Now right click the text box and goto properties and change the name to URLBox and the text to URL then scroll down and find the size setting and change the width to a size according to your form.

So now your form should look like this:
Posted Image

Now right click one of your picture buttons and goto properties and find the image setting and change the image to what you want. Repeat for the rest and you'll have:
Posted Image

Now right click the web browser and goto properties and set it's name to webBrowser and it's URL to a web site like Google or something.

OK now for some actual code.:)

Double click the back button on the tool strip and add this code.
webBrowser.GoBack();
That does exactly what you would think it does.

OK double click the forward button on the tool strip and add this code.
webBrowser.GoForward();

Now double click the home button on the tool strip and add this code.
webBrowser.GoHome();


Now double click the stop button on the tool strip and add this code.
webBrowser.Stop();

Then double click the refresh button on the tool strip and add this code.
webBrowser.Refresh();

Now the last thing we need to do is make our address bars text usable for the web browser to navigate with.

So what we do is add code to our Go button.
webBrowser.Navigate(URLBox.Text);
(tip don't forget http:// when typing in the address bar)

Congratulations you just made your own web browser.:)
I hope you enjoyed this tutorial, as always +rep and comments/questions are welcome.:)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#2
James.H

James.H

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 866 posts
Cool made a new browser :) + rep!

#3
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Thanks.:)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#4
Bartimäus

Bartimäus

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
nice tut + rep (sorry i can't rep you at the moment try it later again)
[SIGPIC][/SIGPIC]

#5
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Thanks.:)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#6
cismarel

cismarel

    Learning Programmer

  • Members
  • PipPipPip
  • 37 posts
Thanks for tut! But how can the adress bar show the page where I am?

#7
gokuajmes

gokuajmes

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 518 posts

Bartimäus said:

nice tut + rep (sorry i can't rep you at the moment try it later again)

Thats one Big Avatar you got :w00t:

#8
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts

Quote

Thanks for tut! But how can the adress bar show the page where I am?
This should do the trick: :)
textBox1.Text = Convert.ToString(webBrowser1.Url);

A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#9
cismarel

cismarel

    Learning Programmer

  • Members
  • PipPipPip
  • 37 posts
thank you thegamemaker, now I have another question. When I type and adress into the textbox i want to navigate to that adress by pressing enter instead of pressing click on the Go button.


#10
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts

Quote

thank you thegamemaker, now I have another question. When I type and adress into the textbox i want to navigate to that adress by pressing enter instead of pressing click on the Go button.
Im pretty sure you could do this:
private void textBox1_KeyDown(KeyEventArgs keyEvent)
        {
            if (keyEvent.KeyCode == Keys.Enter)
            {
                webBrowser1.Navigate(url);
            }
        }

A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#11
cismarel

cismarel

    Learning Programmer

  • Members
  • PipPipPip
  • 37 posts
private void URLBox_KeyDown(KeyEventArgs keyEvent)
{
if (keyEvent.KeyCode == Keys.Enter)
{
webBrowser.Navigate(URLBox.Text);
}


i've tried this, but it didn't work

#12
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
OK what is the error you are getting? Or does it just not work?
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users