如何知道表单是否悬停在组件上?

时间:2010-08-25 05:08:28

标签: delphi forms components

我需要知道(移动)表单是否悬停在某个组件上(可能是没有鼠标的MouseEnter和MouseLeave)。

我有这个想法,即获取组件的左,上,高,宽,并计算(移动)表单的位置是否在表单的位置内。 (我不确定如何做到这一点)

有关实施我的想法的任何建议?还有其他办法吗?

1 个答案:

答案 0 :(得分:5)

尝试这样的事情:

var
  P: TPoint;  
  R1, R2, I: TRect;
begin
  P := TheComponent.ClientOrigin;
  R1 := TheComponent.ClientRect;
  Windows.OffsetRect(R1, P.X, P.Y);
  P := TheForm.ClientOrigin;
  R2 := TheForm.ClientRect;
  Windows.OffsetRect(R2, P.X, P.Y);
  if Windows.IntersectRect(I, R1, R2) then
    // the Form is over the component
  else
    // the Form is not over the component
end;