我使用win-forms
创建了这个简单的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。
答案 0 :(得分:1)
只是手动为“form1.designer.cs”中的后退和前进按钮添加了事件处理程序。它们可能会被删除有几个原因。