windowsforms-devexpress-dot-xtralayout-dot-layoutcontrol-dot-calchitinfo-x28-system-dot-drawing-dot-point-x29.md
Returns information on the layout elements located at the specified point.
Namespace : DevExpress.XtraLayout
Assembly : DevExpress.XtraLayout.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
public BaseLayoutItemHitInfo CalcHitInfo(
Point hitPoint
)
Public Function CalcHitInfo(
hitPoint As Point
) As BaseLayoutItemHitInfo
| Name | Type | Description |
|---|---|---|
| hitPoint | Point |
A Point structure which specifies the test point coordinates relative to the layout controls top-left corner.
|
| Type | Description |
|---|---|
| BaseLayoutItemHitInfo |
A BaseLayoutItemHitInfo object which contains information about the layout elements located at the test point.
|
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.
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.
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();
}
}
}
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports DevExpress.XtraLayout
Imports DevExpress.XtraLayout.HitInfo
Namespace LayoutControl_CalcHitInfo
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub layoutControl1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles layoutControl1.MouseDown
Dim lc As LayoutControl = TryCast(sender, LayoutControl)
Dim hi As BaseLayoutItemHitInfo = lc.CalcHitInfo(e.Location)
Dim currentItem As LayoutControlItem = TryCast(hi.Item, LayoutControlItem)
If currentItem Is Nothing OrElse hi.HitType <> LayoutItemHitTest.TextArea Then
Return
End If
If currentItem.Control IsNot Nothing Then
currentItem.Control.Focus()
End If
End Sub
End Class
End Namespace
See Also