1
我用雙贏的形式Web瀏覽器控件錯誤
namespace WebBrowser
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Load the user's home page.
webBrowser1.GoHome();
}
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Navigate(textBox1.Text);
textBox1.Text = webBrowser1.Url.ToString();
}
private void Navigate(String address)
{
if (String.IsNullOrEmpty(address)) return;
if (address.Equals("about:blank")) return;
if (!address.StartsWith("http://") &&
!address.StartsWith("https://"))
{
address = "http://" + address;
}
try
{
webBrowser1.Navigate(new Uri(address));
}
catch (System.UriFormatException)
{
return;
}
}
private void backButton_Click(object sender, EventArgs e)
{
if (webBrowser1.CanGoBack)
{
webBrowser1.GoBack();
}
else
backButton.Enabled = false;
}
private void forwardButton_Click(object sender, EventArgs e)
{
if (webBrowser1.CanGoForward)
{
webBrowser1.GoForward();
}
else
forwardButton.Enabled = false;
}
private void button2_Click(object sender, EventArgs e)
{
webBrowser1.GoHome();
}
private void button3_Click(object sender, EventArgs e)
{
webBrowser1.Stop();
}
private void button4_Click(object sender, EventArgs e)
{
if (!webBrowser1.Url.Equals("about:blank"))
{
webBrowser1.Refresh();
}
}
}
}
',一切完美,除了前進和後退按鈕使這個簡單的網頁瀏覽器。我已經爲兩者添加了事件處理程序。請指出錯誤。我使用visual studio 2010 ultimate。
你有沒有試過這個: http://stackoverflow.com/questions/7873632/adding-back-and-forward-button-for-webbrowser-control –
沒有工作意味着,它沒有擊中事件處理程序或其他東西? –
使用你的代碼,我挺身而出,恢復正常工作。在前端和後端的處理程序中設置一個斷點。他們受傷了嗎? – Gareth