HtmlDocument.GetElementFromPoint(Point) Method

Definition

Retrieves the HTML element located at the specified client coordinates.

C#
public System.Windows.Forms.HtmlElement GetElementFromPoint(System.Drawing.Point point);
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

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

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also