how to winform texboxt Text transfer value web page textbox

荒凉一梦 提交于 2020-01-06 02:45:11

问题


I have textbox1, I want to transfer textbox1.Text into webbrowser1 web page textbox, how to do this?

I have below code, but webpage text box selected index change event not fired. How to do this?

private void button2_Click(object sender, EventArgs e)
{
    HtmlDocument doc = webBrowser1.Document;
    HtmlElement HTMLControl2 = doc.GetElementById("flightno-filter");
    //HTMLControl.Style = "'display: none;'";
    if (HTMLControl2 != null)
    {
        // HTMLControl2.Style = "display: none";
        HTMLControl2.InnerText = textBox1.Text;
    }
}

Please see below image


回答1:


You're trying to input text to webpage then make make the webbrowser raise the change/input event of the input box? You have to invoke "onChange" event or some other event.

Bellow I make WebBrowser raise keydown event, use SendKey:

private void button2_Click(object sender, EventArgs e)
{
    HtmlDocument doc = webBrowser1.Document;
    HtmlElement HTMLControl2 = doc.GetElementById("flightno-filter");
    //HTMLControl.Style = "'display: none;'";
    if (HTMLControl2 != null)
    {
        // HTMLControl2.Style = "display: none";
        HTMLControl2.InnerText = textBox1.Text;

        HTMLControl2.Focus();              // Set focus to input box
        SendKeys.SendWait("{Right}");      // Send "Right" key
        textBox1.Focus();                  // Give focus back for one of WinForms control

    }
}


来源:https://stackoverflow.com/questions/35746719/how-to-winform-texboxt-text-transfer-value-web-page-textbox

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