KB Article T1029952
Visible to All Users

Get information about the UI elements located at the specified point - WinForms Cheat Sheet

DevExpress WinForms Cheat Sheets, Best Practices and Troubleshooting


Most DevExpress UI controls consist of multiple visual elements (e.g., bands, panels, buttons). These compound controls feature similar CalcHitInfo methods. They allow you to check what visual element is located under the mouse pointer. You can call this method inside click event handlers to show menus or tooltips for elements that do not natively support them.

The list of CalcHitInfo methods for major DevExpress WinForms controls:

You can find a complete list of controls that support the CalcHitInfo method in our documentation by entering "CalcHitInfo" in the API list filter: WinForms Controls - CalcHitInfo


Examples

Handle a click on a Data Grid band button

The Data Grid Band Panel Button does not do anything when users click it. You can change that if you handle any Mouse~ event and use the BandedGridView.CalcHitInfo method to determine which visual element a user has clicked.

Code Example
C#
private void bandedGridView1_MouseDown(object sender, MouseEventArgs e) { var view = sender as BandedGridView; var hitInfo = view.CalcHitInfo(e.Location); if (hitInfo.HitTest == DevExpress.XtraGrid.Views.BandedGrid.ViewInfo.BandedGridHitTest.BandButton) { //your code } }

Show a context menu for the XtraTabControl page header

To accomplish this task, use the XtraTabControl.CalcHitInfo method to determine whether the TabControl's page header is under the current mouse pointer position. If yes, show a context menu built with our WinForms Popup Menu. Refer to the following cheat sheet to learn more about our menus: DevExpress WinForms Cheat Sheets - Context Menus.

Code Example
C#
XtraTabPage contextPage; private void xtraTabControl1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { if(e.Button == MouseButtons.Right) { XtraTabControl tabCtrl = sender as XtraTabControl; Point pt = MousePosition; XtraTabHitInfo info = tabCtrl.CalcHitInfo(tabCtrl.PointToClient(pt)); if(info.HitTest == XtraTabHitTest.PageHeader) { contextPage = info.Page; popupMenu1.ShowPopup(pt); } } }

Show a tooltip for a TreeList cell

Handle the GetActiveObjectInfo event of our ToolTipController component to create the ToolTipControlInfo object (see DevExpress WinForms Cheat Sheet - Tooltips and Hints). To retrieve the hovered TreeList cell, use the TreeList.CalcHitInfo method.

Code Example
C#
private void toolTipController1_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e) { if(e.SelectedControl is DevExpress.XtraTreeList.TreeList) { TreeList tree = (TreeList)e.SelectedControl; TreeListHitInfo hit = tree.CalcHitInfo(e.ControlMousePosition); if(hit.HitInfoType == HitInfoType.Cell) { object cellInfo = new TreeListCellToolTipInfo(hit.Node, hit.Column, null); string toolTip = string.Format("{0} (Column: {1}, Node ID: {2})", hit.Node[hit.Column], hit.Column.Caption, hit.Node.Id); e.Info = new DevExpress.Utils.ToolTipControlInfo(cellInfo, toolTip); } } }

Help us improve this article

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.