vb.net如何读取WebBrowser中鼠标选择的文字
我在Form1中添加一个WebBrowser控件,一个Button,一个textbox,在webBrowser的URL的属性设为www.baidu.com,运行后,会在w...
我在Form1中添加一个WebBrowser控件,一个Button,一个textbox,在webBrowser的URL的属性设为www.baidu.com,运行后,会在webBrowser中呈现百度的主页,用鼠标选中百度主页中的文字,如何实现只有一单击按钮,就将选中的文字呈现中txtbox中?是否可以实现?如何能,请告诉如何做?如果不能,有如何借有API中的Hook来实现?我的邮箱是qingping19880222@163.com
展开
2011-03-29
展开全部
添加引用:Microsoft.mshtml,然后代码如下即可:
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)
'tbKeyWord.Text = range.text;
End If
End If
End Sub
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)
'tbKeyWord.Text = range.text;
End If
End If
End Sub
展开全部
l object library
2 在窗体中添加如下代码
Public WithEvents M_Dom As MSHTML.HTMLDocument '屏蔽ie左键选择
Private Function M_Dom_onselectstart() As Boolean
M_Dom_onselectstart = False
End Function
在webbrowser控件的DocumentComplete事件中添加如下代码
Set M_Dom= webContent.Document
2 在窗体中添加如下代码
Public WithEvents M_Dom As MSHTML.HTMLDocument '屏蔽ie左键选择
Private Function M_Dom_onselectstart() As Boolean
M_Dom_onselectstart = False
End Function
在webbrowser控件的DocumentComplete事件中添加如下代码
Set M_Dom= webContent.Document
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询