Skip to main content

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