LayoutControl.CalcHitInfo(Point) Method
Returns information on the layout elements located at the specified point.
Namespace: DevExpress.XtraLayout
Assembly: DevExpress.XtraLayout.v19.1.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
hitPoint | Point | A Point structure which specifies the test point coordinates relative to the layout controls top-left corner. |
Returns
Type | Description |
---|---|
BaseLayoutItemHitInfo | A BaseLayoutItemHitInfo object which contains information about the layout elements located at the test point. |
Remarks
Use the CalcHitInfo method to determine which element is located at the specified point. For instance, this can be used when handling the layout control’s Click event to determine which element was clicked. In such cases, pass the current mouse pointer’s coordinates as the method’s parameter.
Example
This example shows how to focus a control within a LayoutControl when a corresponding label is clicked. In the MouseDown event handler, the CalcHitInfo method is used to access a layout item at the current mouse position. If the layout item has a control, the control is focused.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-access-an-item-located-at-a-specific-point-e2100
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraLayout;
using DevExpress.XtraLayout.HitInfo;
namespace LayoutControl_CalcHitInfo {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void layoutControl1_MouseDown(object sender, MouseEventArgs e) {
LayoutControl lc = sender as LayoutControl;
BaseLayoutItemHitInfo hi = lc.CalcHitInfo(e.Location);
LayoutControlItem currentItem = hi.Item as LayoutControlItem;
if (currentItem == null || hi.HitType != LayoutItemHitTest.TextArea) return;
if(currentItem.Control != null)
currentItem.Control.Focus();
}
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference 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.