共用方式為


HtmlDocument.GetElementFromPoint(Point) 方法

定義

取得位於指定用戶端座標的 HTML 元素。

public:
 System::Windows::Forms::HtmlElement ^ GetElementFromPoint(System::Drawing::Point point);
public System.Windows.Forms.HtmlElement GetElementFromPoint(System.Drawing.Point point);
public System.Windows.Forms.HtmlElement? GetElementFromPoint(System.Drawing.Point point);
member this.GetElementFromPoint : System.Drawing.Point -> System.Windows.Forms.HtmlElement
Public Function GetElementFromPoint (point As Point) As HtmlElement

參數

point
Point

元素在螢幕上相較於文件左上角的 x,y 位置。

傳回

HtmlElement 文件中指定的螢幕位置。

範例

以下程式碼範例偵測到文件上的點擊,找到該元素,並用 ScrollIntoView 它將該元素與網頁頂端對齊。

private void Document_Click(Object sender, HtmlElementEventArgs e)
{
    if (webBrowser1.Document != null)
    {
        HtmlElement elem = webBrowser1.Document.GetElementFromPoint(e.ClientMousePosition);
        elem.ScrollIntoView(true);
    }
}
Private Sub Document_Click(ByVal sender As Object, ByVal e As HtmlElementEventArgs)
    If (WebBrowser1.Document IsNot Nothing) Then
        Dim Elem As HtmlElement = WebBrowser1.Document.GetElementFromPoint(e.ClientMousePosition)
        Elem.ScrollIntoView(True)
    End If
End Sub

備註

GetElementFromPoint 使用用戶端座標,文件左上角被賦予值 (0,0)。 可透過該 Position 屬性取得游標當前位置的客戶端座標。

適用於

另請參閱