如何从winform文本框中触发事件触发的网页文本框

时间:2016-03-03 09:38:30

标签: c# winforms webbrowser-control

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

 if(open.Count==close.Count)
       {
        foreach(var openi in open)
        {
            foreach(var closei in close)
            {
               if( openi != closei)
               {

               }
               else { return "failed"; }
            }
        }

        }
        else{return "count failed";}

        return "";

enter image description here

enter image description here

2 个答案:

答案 0 :(得分: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();

    }
}

其他任何东西都是默认的。

答案 1 :(得分:0)

 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();
}