【问题标题】:how to winform texboxt Text transfer value web page textbox如何winform文本框文本传递值网页文本框
【发布时间】:2016-03-02 12:04:46
【问题描述】:

我有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;
    }
}

请看下图

【问题讨论】:

  • 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; } } 但 webbrowser 选择 indexchange 事件未触发
  • 通过编辑将代码添加到您的帖子中,因为您可以在 cmets 部分看到它不可读。
  • 哪个事件没有被触发?请添加该代码

标签: c# winforms c#-4.0 textbox webbrowser-control


【解决方案1】:

您正在尝试向网页输入文本,然后让网络浏览器引发输入框的更改/输入事件?您必须调用“onChange”事件或其他事件。

下面我让 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

    }
}

【讨论】:

  • 感谢您的回复 :) 它对我有用.. 非常感谢您,
  • 以及如何触发 onclick 事件?
  • 那是另一个问题,因为你没有在上面的问题中问它。创建新问题并描述您正在使用哪个网站(URL),您尝试点击哪个元素,您尝试了什么(描述需要详细,否则人们会从您那里停靠点)。
  • 对。如果你问新的并在这里评论通知我,我可以帮助你:)
  • heathrow.com/arrivals我有这个网站,也想要同样的功能;(怎么做,这个网页文本框文件onclick事件@Sakura
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多