elementFromPoint 方法

       

给定屏幕坐标即可返回对应于指定坐标参数的 IHTMLElement 对象。

expression.elementFromPoint(x, y)

expression  必选。返回“应用于”列表中的对象之一的表达式。

x  必选。Long 类型。代表横轴上的指定点。

y  必选。Long 类型。代表纵轴上的指定点。

说明

此处的坐标对应于窗口坐标(0,0 指窗口的左上角)。若要使 elementFromPoint 方法表现出预期的效果,位于 (x, y) 的对象或元素必须支持和响应鼠标事件。

示例

下列示例提示用户输入 x 和 y 坐标来指定元素的位置。如果元素与指定的位置相符,则会显示元素的标记名称。如果此处没有相应的元素,则会向用户显示消息。

Sub GetElement()
'Returns an HTML element that corresponds to a set of coordinates

    Dim objApp As FrontPage.Application
    Dim objDoc As DispFPHTMLDocument
    Dim objElement As IHTMLElement
    Dim lngX As Long
    Dim lngY As Long

    Set objApp = FrontPage.Application
    Set objDoc = objApp.ActiveDocument
    'Prompt user for coordinates.
    lngX = InputBox("Enter the X position of the element you want to select.")
    lngY = InputBox("Enter the Y position of the element you want to select.")
    'Get the element based on the user's coordinates.
    Set objElement = objDoc.elementFromPoint(lngX, lngY)

    'If the search was succesful, display message
    If objElement Is Nothing Then
        MsgBox "The specified coordinates did not return an element."
    Else
        'Otherwise display message
        MsgBox "The element is of type " & objElement.tagName & "."
    End If

End Sub