如何获得鼠标点击处的控件名称或ID
答案:1 悬赏:60 手机版
解决时间 2021-04-13 00:32
- 提问者网友:疯子也有疯子的情调
- 2021-04-12 09:14
如何获得鼠标点击处的控件名称或ID
最佳答案
- 五星知识达人网友:冷風如刀
- 2021-04-12 10:46
添加一个webbrowser,一个textbox并设置允许多行显示,一个panel控件。名称均默认
Public Class Form1
Dim GetObj As Boolean
Dim HtmlObj As HtmlElement
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Web.Navigate(InputBox("请输入网址,例如:;, "导航到", ";))
End Sub
Private Sub Panel1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
GetObj = True
End Sub
Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
If GetObj Then
Dim PointFromWeb As Point = Web.PointToClient(MousePosition)
Dim tmp As HtmlElement = Web.Document.GetElementFromPoint(PointFromWeb)
If Not tmp.Equals(HtmlObj) Then
HtmlObj = tmp
Me.Text = HtmlObj.Id & " name: " & HtmlObj.Name
TextBox1.Text = HtmlObj.InnerHtml
End If
End If
End Sub
Private Sub Panel1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp
GetObj = False
End Sub
End Class
用法:
拖拽panel到webbrowser上的控件
Public Class Form1
Dim GetObj As Boolean
Dim HtmlObj As HtmlElement
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Web.Navigate(InputBox("请输入网址,例如:;, "导航到", ";))
End Sub
Private Sub Panel1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
GetObj = True
End Sub
Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
If GetObj Then
Dim PointFromWeb As Point = Web.PointToClient(MousePosition)
Dim tmp As HtmlElement = Web.Document.GetElementFromPoint(PointFromWeb)
If Not tmp.Equals(HtmlObj) Then
HtmlObj = tmp
Me.Text = HtmlObj.Id & " name: " & HtmlObj.Name
TextBox1.Text = HtmlObj.InnerHtml
End If
End If
End Sub
Private Sub Panel1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp
GetObj = False
End Sub
End Class
用法:
拖拽panel到webbrowser上的控件
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯