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 用戶端座標。

適用於

另請參閱