Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys....
i created a simple web browser with a tool strip and web browser and written code and it is working fine and
what happening is when i click on home button. it was going to the home page which was set in internet explorer... it was fine, but what i want is when i click home button the text field, which i used to enter url also should change,
for example when i type www.facebook.com it was navigating to facebook and later onward the text in the text box was not changing and if we click any of the button like back, forward, home. the text in the textbox should be changed resepective to the webbrowser's url...
the code for that is...

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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

        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            webBrowser1.Navigate(toolStripTextBox1.Text);
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            webBrowser1.GoBack();
//here the toolstrip text box should display the previous web page url instead of typed one//
       }

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

//here the toolstrip texbox should display the next page url instead of typed one..

        }

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

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

        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            webBrowser1.GoHome();
// here the toolstrip textbox should get the url of the home page instead of the typed one//
        }


    }
}
Posted
Updated 20-Jun-14 0:35am
v2
Comments
Suvabrata Roy 20-Jun-14 6:33am    
Hi,

toolStripButton6 which button is this. you are useing this button to navigate so after entering the URL click on this button.
chaitanya556 20-Jun-14 6:36am    
tootlsrtipbutton6 is go button....
Suvabrata Roy 20-Jun-14 6:38am    
So you I think your go button is working fine.

are you want to know how to navigate without click on go button ?
chaitanya556 20-Jun-14 6:41am    
of course, i too want that, what i want is when i enter url in textbox. it was navigating but when we proceed to further page, the text in textbox should change to specific url...when we enter www.facebook.com and press go button it was redirecting to facebook page and when we pres home button it was going to google.co.in but the text in the textbox is still www.facebook.com and the page displaying is google.co.in

you can use WebBrowser.Navigating Event[^] and set the URL to TextBox
C#
public Form1()
{
    InitializeComponent();
    webBrowser1.Navigating += 
    new WebBrowserNavigatingEventHandler(webBrowser1_Navigating);
}
private void webBrowser1_Navigating(object sender, 
    WebBrowserNavigatingEventArgs e)
{
    TextBox1.Text =e.Url.ToString();
}
 
Share this answer
 
Comments
chaitanya556 20-Jun-14 7:06am    
can i have a progress bar in my browser? and if i can, how should i write code for that?
Hi,


You can use KeyPress event of textbox to navigate, on keypress event you will get which key has been pressed if the key is Enter then navigate to written URL

For KeyPress : http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress(v=vs.110).aspx[^]

Second there is a event of WebBrowser named OnNavigated you can use it to get the URL where your browser is navigating and set taht to your textbox.

Web Browser Events : http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser(v=vs.110).aspx[^]

OnNavigated : http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.onnavigated(v=vs.110).aspx[^]

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900