Karthick
Karthick

Reputation: 113

How to show address bar in WebBrowser control

How to show address bar in WebBrowser control in a Windows Form?

Upvotes: 6

Views: 17252

Answers (3)

JonH
JonH

Reputation: 33153

Drag and drop a text box into your form. Use the URL.ToString method to set the textbox .text value to that 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(); 
    } 

Upvotes: 0

Cory Charlton
Cory Charlton

Reputation: 8938

I could be mistaken but I don't believe the WebBrowserControl includes the address bar, toolbar, etc. I believe you'll have to create your own address bar. You could use the Navigated or Navigating events to determine when the URL is changing and update 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 a TextBox named textBox1, a Button named button1 and a WebBrowserControl named webBrowser1

Upvotes: 8

jose
jose

Reputation: 2543

You could make a textbox and then fill it with the site property i think

Upvotes: 0

Related Questions