VB.NET - 将数据推送到网页内的TextArea

时间:2013-11-26 22:29:48

标签: vb.net winforms internet-explorer browser textarea

我目前正在开发一个WinForm VB.NET应用程序。

我想添加一个函数,它将文本从我的表单中的TextBox传递到Internet Explorer中打开的网页中的特定TextArea。

不要想要使用WebBrowser。我知道这种方式可能,但就我而言,我需要使用Internet Explorer。

提前谢谢!

编辑:这个应用程序是一个与Windows的剪贴板一起工作的宏程序。在工作中,我们有WEB软件BMC Remedy。大多数情况下,字段“Resolution”包含相同的文本。为了节省一些时间,当按下一个宏(例如:CTRL + NumPad1)时,程序将文本“链接”到该宏(例如:“重新启动计算机!”)到剪贴板中。然后我们可以在BMC Remedy页面的TextArea中执行CTRL + V.但如果文本在没有CTRL + V的情况下将自己置于TextArea中,对用户来说会更好。

1 个答案:

答案 0 :(得分:0)

您需要添加到项目中的COM;

  • Microsoft Internet Controls
  • Microsoft HTML对象库

也许这不是最好的方法,但它正在发挥作用。我不是作者或代码。

http://www.codeproject.com/Articles/14161/

玩得开心!

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim SWs As New SHDocVw.ShellWindows
    Dim IE As SHDocVw.InternetExplorer

    For Each IE In SWs
        If IE.Name = "Internet Explorer" Then
            If IE.LocationName <> "" And IE.LocationURL <> "about:Tabs" And IE.LocationURL <> "about:blank" Then

                Dim HTMLDoc As mshtml.HTMLDocument
                HTMLDoc = IE.Document

                Dim iHTMLCol As IHTMLElementCollection
                Dim iHTMLEle As IHTMLElement
                Dim strId As String

                iHTMLCol = HTMLDoc.getElementsByTagName("textarea")

                'Put the text into the TextArea
                For Each iHTMLEle In iHTMLCol
                    If Not iHTMLEle.getAttribute("id") Is Nothing Then
                        strId = iHTMLEle.getAttribute("id").ToString
                        If strId = "NAME OF YOUR FIELD" Then
                            iHTMLEle.setAttribute("value", "YOUR TEXT RIGHT HERE")
                        End If
                    End If
                Next
            End If
        End If
    Next

End Sub