在WebBrowser Control C#中编辑文本框内容后接收事件

发布于 2025-01-31 09:47:44 字数 672 浏览 0 评论 0原文

我有以下问题:

我正在使用C#Winforms中的WebBrowser控件,以导航到包含文本框的特定URL。现在,我想在用户输入这些文本框中的文本后采取行动。我已经尝试了webbrowser.document.body.keydown,keyup和键盘事件。只有键盘被触发,这很好,但是当启动文本框的内容时,它仍然没有变化(因为我在到特定的文本框之前收到了该事件)。

因此,我尝试了很少的解决方法,以启动一个具有较小延迟的新线程,这将造成魔术,但是在创建的线程中,我无法访问webbrowser.document属性,因为:

Specified cast is not valid

是否有一些合适的方法来解决我遇到的问题?感谢您的帮助

编辑1: 在暗示模糊和变更事件之后,我发现Intput事件应该做我想做的事情。但是,它有一些缺陷:第一次单击文本框后,第一个键按效果很好,但是另一个键则没有执行。但是,当我将重点放在元素中并再次单击它时,它可以正常工作,但是当我从字段的开头开始写入时,在某些情况下会忽略事件。

HtmlElement element = webbrowser.Document.GetElementFromPoint(e.ClientMousePosition);
element.AttachEventHandler("oninput", func);

i have following problem:

I'm using webbrowser control in c# winforms, to navigate to specific url which contains textboxes. Now i would like to act after user enters text inside these textboxes. I've tried the Webbrowser.Document.Body.keydown, keyup and keypress events. Only keypress gets fired, which would be fine but when it fires the content of textbox is still unchanged (as i received the event before it got to specific textbox).

So i tried little workaround, to start a new thread with small delay that would do the magic, but in the created thread I cannot access Webbrowser.Document property because :

Specified cast is not valid

Is there some suitable way to solve the problem I have? Thanks for your help

Edit1:
After suggestion of blur and change events, i found that event oninput should do what I want. However, it has some flaw: After i click inside the textbox for the first time, the first key press works fine, however the other are not executed. But when I focus out of the element and click inside it again, it works fine, but when i start to write from the start of the field it ignores the event in some cases..

HtmlElement element = webbrowser.Document.GetElementFromPoint(e.ClientMousePosition);
element.AttachEventHandler("oninput", func);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文