Skip to main content

How to Determine a Visual Element Under the Mouse Pointer

The following example demonstrates how to provide hints for the Customization Form‘s Available Items and Layout Tree View panes using the layout control’s GetHitTest method, the TTimer.OnTimer event, and the TcxHintStyleController component.

uses
// ...
  Controls, cxControls, cxHint;
// ...
procedure <Form>.<Timer>Timer(Sender: TObject);
var
  AHitTest: TdxCustomLayoutHitTest;
  AHintPoint: TPoint;
begin
  AHitTest := <dxLayoutControl>.GetHitTest(<dxLayoutControl>.ScreenToClient(GetMouseCursorPos));
  case (AHitTest.HitTestCode) of
    htAvailableItems:
    begin
      AHintPoint := GetMouseCursorPos;
      <cxHintStyleController>.ShowHint(AHintPoint.X, AHintPoint.Y + 25, 'Available Items pane:', 'Create new layout elements, or change the visibility of existing elements');
    end;
    htTreeViewItems:
    begin
      AHintPoint := GetMouseCursorPos;
      <cxHintStyleController>.ShowHint(AHintPoint.X, AHintPoint.Y + 25, 'Layout Tree View pane:', 'Rearrange layout elements');
    end;
    else
      <cxHintStyleController>.HideHint;
  end;

The following image shows the result of executing the code:

See Also