Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Access an item located at a specific point

  • 2 minutes to read

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();
        }
    }
}