如何将按 Enter 键发送到网页浏览器控件中的 htmlelement

问题描述 投票:0回答:1

我正在开发包含网络浏览器控件的win表单应用程序,在网页中有 一个文本框字段,我将其作为 htmlelement 获取..

我用字符串值正确填写它,然后我想发送回车键来提交 其中的价值..

这是我到目前为止的代码:

HtmlDocument hd = wbr.Document;//wbr is web browser control
HtmlElement he = hd.GetElementById("response_field");
he.SetAttribute("value", ans);//filled correctly 
wbr.Select();
he.Focus();
he.InvokeMember("submit");
SendKeys.Send("{ENTER}");

我尝试过调用成员,尝试过发送密钥,但都不起作用..

如何做到这一点?

c# webbrowser-control
1个回答
0
投票

来自 MSDN - 导航

// Navigates to the URL in the address box when 
// the ENTER key is pressed while the ToolStripTextBox has focus.
private void toolStripTextBox1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        Navigate(toolStripTextBox1.Text);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.