I made this simple web browser using win-forms
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();
}
}
}
}
` ,everything works perfectly except the back and forward buttons. I've added event handlers for both. please point out the errors.I use visual studio 2010 ultimate.
刚刚在“ form1.designer.cs”中手动添加了用于后退和前进按钮的事件处理程序。它们可能由于多种原因而被删除。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.