This documentation is archived and is not being maintained.

HtmlDocument.GetElementFromPoint Method

Retrieves the HTML element located at the specified client coordinates.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public HtmlElement GetElementFromPoint(
	Point point
)

Parameters

point
Type: System.Drawing.Point

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

Return Value

Type: System.Windows.Forms.HtmlElement
The HtmlElement at the specified screen location in the document.

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.

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.

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Show: