C#Web浏览器Enter键

时间:2013-08-30 09:58:04

标签: c# winforms

使用Enter键浏览浏览器时遇到问题。

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    switch (keyData)
    {
        case Keys.Enter:
            go_Click.PerformClick();
            return true;
    }
    return false;
}

我的go_Click

private void go_Click(object sender, EventArgs e)
{
    //declares URL as string variable
    string url = textbox.Text;

    //if statment to determine if URL is correct
    if (url == "")
    {
        MessageBox.Show("Please enter a valid URL!");
    }

    if (url.Substring(0, 3) == "www")
    {
        url = "http://" + url;
        webBrowser1.Navigate(url);
    }
}

它返回一个错误,错误表明这是一个方法,在给定的上下文中无效。

1 个答案:

答案 0 :(得分:1)

更改此行代码go_Click.PerformClick();

go_Click(null, null);