问题
How to show address bar in WebBrowser control in a Windows Form?
回答1:
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
回答2:
You could make a textbox and then fill it with the site property i think
回答3:
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();
}
来源:https://stackoverflow.com/questions/1923740/how-to-show-address-bar-in-webbrowser-control