• Register now to get access to thousands of Tutorials, Leaked content, Hot NSFW and much more. Join us as we build and grow the community.

Advertise Here

Advertise Here

Advertise Here

How to create your Own Web Browser Using C#

mikaelmax99

Ad Placement Specialist
M Rep
0
0
0
Rep
0
M Vouches
0
0
0
Vouches
0
Posts
132
Likes
49
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 2 1000 XP
In this tutorial I’m going to teach how to create your own Web Browser Using C#. This lesson will also involve the use of some very common tools such as Buttons and WebBrowser. To start building this application, let’s create a new project and call it as “WebBrowser” then design it that looks like as shown below.
web_browser.png


If you have find difficulties in finding the WebBrowser Tool you can follow it in the image provided below.
web2.png


Next, on the “Go” button, double click it and add the following code:
  1. private

    void

    button1_Click(

    object

    sender, EventArgs e)
  2. {
  3. webBrowser1.

    Navigate

    (

    textBox1.

    Text

    )

    ;
  4. }

In the code above, we simply assign a web URL from the textbox to the browser. And it loads the document at the specified Uniform Resource Locator based on the user input.
Then we need also to add code for our “Back” button. This back button takes you to the last page stored in the web browser. And here’s the following code.
  1. private

    void

    btnBack_Click(

    object

    sender, EventArgs e)
  2. {
  3. webBrowser1.

    GoBack

    (

    )

    ;
  4. }

Next, for the “Forward” button, this button allows you to move to the next page in the navigation history, if one is available. And here’s the following code.
  1. private

    void

    btnForward_Click(

    object

    sender, EventArgs e)
  2. {
  3. webBrowser1.

    GoForward

    (

    )

    ;

  4. }

And also for the “Refresh” button, here’s the following code:
  1. private

    void

    btnRefresh_Click(

    object

    sender, EventArgs e)
  2. {
  3. webBrowser1.

    Refresh

    (

    )

    ;
  4. }

And if you try to run your application, it will give you some error when navigating the web browser. Because the URL in the textbox is not changing, especially when you click the “Back” or the “Forward” button. So to fix this bug, first select the “Web Browser” on the Form then on the “Properties”, choose “events” or the “lightning icon”. And double click “Navigated”. The process is also shown in the figure below.
web3_0.png


Then add this following code:
  1. private

    void

    webBrowser1_Navigated(

    object

    sender, WebBrowserNavigatedEventArgs e)
  2. {
  3. //gets the URL of the current document and assign to the Textbox
  4. textBox1.

    Text

    =

    webBrowser1.

    Url

    .

    ToString

    (

    )

    ;
  5. }

And you can now press “F5” to your application. And it will look like as shown below.
web4.png


And here’s all the code use for this application.
  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

    webBrowser
  10. {
  11. public

    partial

    class

    Form1 :

    Form
  12. {
  13. public

    Form1(

    )
  14. {
  15. InitializeComponent(

    )

    ;
  16. }

  17. private

    void

    button1_Click(

    object

    sender, EventArgs e)
  18. {
  19. webBrowser1.

    Navigate

    (

    textBox1.

    Text

    )

    ;
  20. }

  21. private

    void

    btnBack_Click(

    object

    sender, EventArgs e)
  22. {
  23. webBrowser1.

    GoBack

    (

    )

    ;
  24. }

  25. private

    void

    btnForward_Click(

    object

    sender, EventArgs e)
  26. {
  27. webBrowser1.

    GoForward

    (

    )

    ;

  28. }

  29. private

    void

    btnRefresh_Click(

    object

    sender, EventArgs e)
  30. {
  31. webBrowser1.

    Refresh

    (

    )

    ;
  32. }

  33. private

    void

    webBrowser1_Navigated(

    object

    sender, WebBrowserNavigatedEventArgs e)
  34. {
  35. //gets the URL of the current document and assign to the Textbox
  36. textBox1.

    Text

    =

    webBrowser1.

    Url

    .

    ToString

    (

    )

    ;
  37. }




  38. }
  39. }


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

452,500

350,639

350,649

Top