将密钥发送到网页浏览器 vb.net?
我的 vb.net 应用程序中有一个网络浏览器,我想在网站的文本框中输入文本。单击按钮 1 时,它会以编程方式查找文本框并在其中键入消息。
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SendKeys.Send("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}")
SendKeys.Send("The text I want to send to the control.")
End Sub
End Class
但是,它不起作用。 Tab 键确实使光标位于正确的位置,但是当将文本粘贴到应用程序中时,应用程序崩溃了。出什么问题了?
I have a webbrowser in my vb.net application and I would like to enter text into a textbox on a site. When button 1 is clicked, it programmatically finds the text box and types the message in.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SendKeys.Send("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}")
SendKeys.Send("The text I want to send to the control.")
End Sub
End Class
However, it doesn't work. The tab keys do get the curser in the right place but when the text is pasted in the application crashes. Whats gone wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要将密钥发送到 WebBrowser,请先获取 WebBrowser 焦点,然后再获取 SendKeys。使用以下代码:
To send keys to WebBrowser, get WebBrowser focus and later SendKeys. Use the following code:
由于您使用的是网络浏览器控件,因此您可以通过名称访问该元素。例如,这会将文本放入 Google 的搜索框中,然后单击 Google 搜索按钮:
Since you are using a webbrowser control, you can access the element by name. For example, this will put text into Google's search box and then click the Google Search button: