본문 바로가기

자료

HtmlDocument.GetElementFromPoint(Point) Method

728x90

Retrieves the HTML element located at the specified client coordinates.

C#
public System.Windows.Forms.HtmlElement GetElementFromPoint (System.Drawing.Point point);

Parameters

point
Point

The x,y position of the element on the screen, relative to the top-left corner of the document.

Returns

HtmlElement

The HtmlElement at the specified screen location in the document.

Examples

The following code example detects a click on the document, finds the element, and uses ScrollIntoView to align the element with the top of the Web page.

C#
private void Document_Click(Object sender, HtmlElementEventArgs e)
{
    if (webBrowser1.Document != null)
    {
        HtmlElement elem = webBrowser1.Document.GetElementFromPoint(e.ClientMousePosition);
        elem.ScrollIntoView(true);
    }
}

Remarks

GetElementFromPoint uses client coordinates, in which the upper-left corner of the document is assigned the value (0,0). Client coordinates for the current position of the cursor can be obtained using the Position property.

Applies to

.NET

5.0 Preview 7

.NET Core

3.1 3.0

.NET Framework

4.8 4.7.2 4.7.1 4.7 4.6.2 4.6.1 4.6 4.5.2 4.5.1 4.5 4.0 3.5 3.0 2.0
728x90