问题
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