vb.net webbrowser控件如何获取鼠…
发布时间:2020-12-17 07:40:39 所属栏目:百科 来源:网络整理
导读:首先添加引用Microsoft.mshtml,具体操作 项目-添加引用-.NET找到添加就行 需要的控件webbrowser一个,button一个,如果名字不是默认请修正代码中控件名字。 然后代码如下即可:在vs2010,【.net4.0下调试通过】Private Sub Button1_Click(ByVal sender As Sy
首先添加引用Microsoft.mshtml,具体操作项目->添加引用->.NET找到添加就行
需要的控件webbrowser一个,button一个,如果名字不是默认请修正代码中控件名字。 然后代码如下即可:在vs2010,【.net4.0下调试通过】 Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click '获取用户选中的文字 Dim htmlDocument As mshtml.IHTMLDocument2 'IHTMLDocument2 htmlDocument = WebBrowser1.Document.DomDocument Dim currentSelection As mshtml.IHTMLSelectionObject currentSelection = htmlDocument.selection Dim range As mshtml.IHTMLTxtRange If Not (currentSelection Is Nothing) Then range = currentSelection.createRange() If Not (range Is Nothing) Then MsgBox(range.text) ‘可以进行你希望的操作 End If End If End Sub (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |