System.Windows.Forms.ListBox.IndexFromPoint Method

Returns the zero-based index of the item at the specified coordinates.

Syntax

public int IndexFromPoint (int x, int y)

Parameters

x
The x-coordinate of the location to search.
y
The y-coordinate of the location to search.

Returns

The zero-based index of the item found at the specified coordinates; returns ListBox.NoMatches if no match is found.

Remarks

This method enables you to determine which item that is located at a specific location within the control. You can use this method to determine which item within the list is selected when a user right-clicks the System.Windows.Forms.ListBox. The location of the cursor can be determined and passed to the x and y parameters of the ListBox.IndexFromPoint(System.Drawing.Point) method to determine which item the user right-clicked the mouse over. You can then display a shortcut menu to the user to provide tasks and features based on the specific item.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0