how to webpage textbox onclick event fire from winform textbox

喜夏-厌秋 提交于 2019-12-26 03:49:33

问题


I have below code,when i search from my winform textbox and click search button but webpage text box onclick event not fired. How to do this? here is :http://www.heathrow.com/arrivals when i click search button page still same position, show in 2nd number image. internet explorer 11 i have installed

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

            }

}


回答1:


Here is the code:

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

    }
}

Anything else is default.




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


来源:https://stackoverflow.com/questions/35768309/how-to-webpage-textbox-onclick-event-fire-from-winform-textbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!