【问题标题】:how to webpage textbox onclick event fire from winform textbox如何从winform文本框触发网页文本框onclick事件
【发布时间】:2016-03-03 09:38:30
【问题描述】:

我有以下代码,当我从我的 winform 文本框搜索并单击搜索按钮但网页文本框 onclick 事件未触发时。这个怎么做?这里是:http://www.heathrow.com/arrivals 当我点击搜索按钮页面仍然相同的位置,显示在第二个数字图像中。 Internet Explorer 11 我已经安装了

private void button2_Click(object sender, EventArgs e)
{
      HtmlDocument doc = webBrowser1.Document;
            HtmlElement HTMLControl2 = doc.GetElementById("searchInput");

            if (HTMLControl2 != null)
            {
                // HTMLControl2.Style = "display: none";
                HTMLControl2.InnerText = textBox1.Text;

                HTMLControl2.Focus();

                SendKeys.SendWait("{ENTER}");
                textBox1.Focus();

            }

}

【问题讨论】:

  • 不清楚你问的是什么。即使我直接在该框中键入字符串aa,然后按Enter,也没有任何反应。那么您期望该页面上的行为是什么?
  • 当您输入足够多的 6 个字符时,该站点将自动处理该文本,如果没有,它将忽略。与浏览器相同。
  • NO search winform 搜索按钮在此站点不起作用;(
  • 等待页面加载完成,输入文本aa6414并点击搜索按钮,您将看到页面处理您的查询。
  • 没有页面仍然相同的位置只有文本框填充;(

标签: c# winforms webbrowser-control


【解决方案1】:

代码如下:

Form1.cs:

private void textBox1_TextChanged(object sender, EventArgs e)
{
    HtmlDocument doc = webBrowser1.Document;
    HtmlElement HTMLControl2 = doc.GetElementById("searchInput");

    if (HTMLControl2 != null)
    {
        // HTMLControl2.Style = "display: none";
        HTMLControl2.InnerText = textBox1.Text;

        HTMLControl2.Focus();

        SendKeys.SendWait("{ENTER}");
        textBox1.Focus();

    }
}

其他都是默认的。

【讨论】:

  • 和我的应用一样 ;(
  • 是的,正如我所说。再做一项测试,页面加载完成后,您复制一个航班号并将其粘贴到您的 winforms 文本框,然后单击搜索以查看是否有任何不同。
  • 这段代码对我有帮助 ;) SendKeys.Send("{ENTER}"); textBox1.Focus(); HTMLControl2.Focus(); HTMLControl2.InnerText = textBox1.Text; SendKeys.Send("{ENTER}"); textBox1.Focus(); HTMLControl2.Focus();
【解决方案2】:
 HtmlDocument doc = webBrowser1.Document;
    HtmlElement HTMLControl2 = doc.GetElementById("searchInput");

    if (HTMLControl2 != null)
    {
        // HTMLControl2.Style = "display: none";
        HTMLControl2.InnerText = textBox1.Text;
                 SendKeys.Send("{ENTER}");
                textBox1.Focus();
               HTMLControl2.Focus();
                HTMLControl2.InnerText = textBox1.Text;
              SendKeys.Send("{ENTER}");
               textBox1.Focus();
              HTMLControl2.Focus();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-25
    • 1970-01-01
    相关资源
    最近更新 更多