How do I know if a Form is hovering over a component?
I need to know if a (moving) form is hovering over a component (maybe something like MouseEnter and MouseLeave without the mouse).
I have this idea of getting the Left, Top, Heigh开发者_StackOverflowt, Width of the component and calculating if the (moving) form's position is within the position of the form. (I'm not exactly sure how I can do this)
Any suggestions on implementing my idea? Is there any other way I can do this?
Try something like this:
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;
精彩评论