我有textbox1
,我想将textbox1.Text
转移到webbrowser1
网页文本框中,该怎么做?
我有以下代码,但网页文本框选择的索引更改事件未被触发。怎么做?
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;
}
}
请参见下图
答案 0 :(得分:1)
您正在尝试将文本输入到网页,然后让webbrowser引发输入框的更改/输入事件?你必须调用“onChange”事件或其他一些事件。
Bellow我让WebBrowser引发keydown事件,使用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
}
}