Back to Devexpress

TreeList.CalcHitInfo(Point) Method

windowsforms-devexpress-dot-xtratreelist-dot-treelist-dot-calchitinfo-x28-system-dot-drawing-dot-point-x29.md

latest6.7 KB
Original Source

TreeList.CalcHitInfo(Point) Method

Returns information about the Tree List’s elements which are located at the specified point.

Namespace : DevExpress.XtraTreeList

Assembly : DevExpress.XtraTreeList.v25.2.dll

NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.TreeList

Declaration

csharp
public TreeListHitInfo CalcHitInfo(
    Point pt
)
vb
Public Function CalcHitInfo(
    pt As Point
) As TreeListHitInfo

Parameters

NameTypeDescription
ptPoint

A Point structure which specifies test point coordinates relative to the Tree List’s top-left corner.

|

Returns

TypeDescription
TreeListHitInfo

A TreeListHitInfo object which contains information about the Tree List’s elements located at the test point.

|

Remarks

Use the CalcHitInfo method to determine which element is located at a specified point. For instance, this can be used when handling the Tree List’s Click event to determine which element was clicked. In such instances, pass the current mouse pointer’s coordinates as the method’s parameter.

Example

The code below obtains the name of the element located under the mouse pointer. The MouseMove event is handled to track mouse pointer movement.

csharp
using DevExpress.XtraTreeList;
//...
private void treeList1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) {
   TreeListHitInfo hi = treeList1.CalcHitInfo(new Point(e.X, e.Y));
   string elementName = hi.HitInfoType.ToString();
   //...
}
vb
Imports DevExpress.XtraTreeList
'...
Private Sub TreeList1_MouseMove(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles TreeList1.MouseMove
   Dim hi As TreeListHitInfo = TreeList1.CalcHitInfo(New Point(e.X, e.Y))
   Dim ElementName As String = hi.HitInfoType.ToString()
   ' ...
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the CalcHitInfo(Point) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-tokenedit-dropdown-with-treelist/CS/TokenEditTest/CustomTokenEditDropDownControl.cs#L73

csharp
void OnTreeListDoubleClick(object sender, EventArgs e) {
    TreeListHitInfo hi = TreeList.CalcHitInfo(TreeList.PointToClient(Control.MousePosition));
    if(hi.HitInfoType == HitInfoType.Cell && GetSelectedDataItem() is TreeListLeaf) {

drag-drop-grid-rows-to-treelist/CS/DragAndDropRows/Form1.cs#L92

csharp
Point pt = treeList.PointToClient(hitPoint);
var ht = treeList.CalcHitInfo(pt);
TreeListNode destNode = ht.Node;

winforms-spreadsheetcontrol-api-part1/CS/SpreadsheetControl/Form1.cs#L149

csharp
TreeList tree = sender as TreeList;
TreeListHitInfo hitInfo = tree.CalcHitInfo(tree.PointToClient(Control.MousePosition));
if (hitInfo.Node != null)

winforms-treelist-customize-cell-tooltip/CS/Form1.cs#L24

csharp
TreeList tree = (TreeList)e.SelectedControl;
TreeListHitInfo hit = tree.CalcHitInfo(e.ControlMousePosition);
if(hit.HitInfoType == HitInfoType.Cell) {

winforms-tokenedit-dropdown-with-treelist/VB/TokenEditTest/CustomTokenEditDropDownControl.vb#L81

vb
Private Sub OnTreeListDoubleClick(ByVal sender As Object, ByVal e As EventArgs) Handles treeList_Renamed.DoubleClick
    Dim hi As TreeListHitInfo = TreeList.CalcHitInfo(TreeList.PointToClient(Control.MousePosition))
    If hi.HitInfoType = HitInfoType.Cell AndAlso TypeOf GetSelectedDataItem() Is TreeListLeaf Then

drag-drop-grid-rows-to-treelist/VB/DragAndDropRows/Form1.vb#L90

vb
Dim pt As Point = treeList.PointToClient(hitPoint)
Dim ht = treeList.CalcHitInfo(pt)
Dim destNode As TreeListNode = ht.Node

winforms-spreadsheetcontrol-api-part1/VB/SpreadsheetControl/Form1.vb#L142

vb
Dim tree As TreeList = TryCast(sender, TreeList)
Dim hitInfo As TreeListHitInfo = tree.CalcHitInfo(tree.PointToClient(Control.MousePosition))
If hitInfo.Node IsNot Nothing Then

winforms-treelist-customize-cell-tooltip/VB/Form1.vb#L24

vb
Dim tree As TreeList = CType(e.SelectedControl, TreeList)
Dim hit As TreeListHitInfo = tree.CalcHitInfo(e.ControlMousePosition)
If hit.HitInfoType = HitInfoType.Cell Then

See Also

TreeList Class

TreeList Members

DevExpress.XtraTreeList Namespace