How to show the address bar in a WebBrowser control

How to show the address bar in a webbrowser control on a windows form?

+5
source share
3 answers

I may be wrong, but I do not believe that WebBrowserControl includes the address bar, toolbar, etc. I believe that you will need to create your own address bar. You can use events Navigatedor Navigatingto determine when the URL changes and updates the text box.

private void button1_Click(object sender, EventArgs e)
{
    if (!string.IsNullOrEmpty(textBox1.Text))
    {
        webBrowser1.Navigate(textBox1.Text);
    }
}

private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
    if (textBox1.Text != e.Url.ToString())
    {
        textBox1.Text = e.Url.ToString();
    }
}

Edit: my form has TextBoxthe name textBox1, a Buttonwith the name button1 and WebBrowserControlwith the name webBrowser1

+7
source

, , ,

0

Drag the text box into your form. Use the URL.ToString method to set the .text text field to this URL string:

Dim strURL As String
        strURL = ""

        If Me.TextBox1.Text.Length = 0 Then
            Me.TextBox1.Focus()
            Me.TextBox1.BackColor = Color.Red
        Else
            If InStr(Me.TextBox1.Text, "http://") = 0 Then
                strURL = "http://" & Me.TextBox1.Text.ToString()
            Else
                strURL = Me.TextBox1.Text.ToString()
            End If
            Me.WebBrowser1.Navigate(New System.Uri(strURL))
            Me.TextBox1.Text = Me.WebBrowser1.Url.ToString()
        End If

Here's C #:

string strURL = null; 
    strURL = ""; 

    if (this.TextBox1.Text.Length == 0) { 
        this.TextBox1.Focus(); 
        this.TextBox1.BackColor = Color.Red; 
    } 
    else { 
        if (Strings.InStr(this.TextBox1.Text, "http://") == 0) { 
            strURL = "http://" + this.TextBox1.Text.ToString(); 
        } 
        else { 
            strURL = this.TextBox1.Text.ToString(); 
        } 
        this.WebBrowser1.Navigate(new System.Uri(strURL)); 
        this.TextBox1.Text = this.WebBrowser1.Url.ToString(); 
    } 
0
source

All Articles