Επεξεργασία

Κοινή χρήση μέσω


HtmlDocument.GetElementFromPoint(Point) Method

Definition

Retrieves the HTML element located at the specified client coordinates.

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

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.

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

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

See also