得到窗体鼠标下面的控件 function TMyClass.GetMouseControl(AForm: TForm): TWinControl; var i: Integer; sc: TPoint; begin result := nil; with AForm do begin sc := ScreenToClient(Mouse.CursorPos); for i := 0 to ComponentCount-1 do begin if AForm.Components[i] is TWinControl then if (sc.X > TWinControl(Components[i]).BoundsRect.Left) and (sc.X < TWinControl(Components[i]).BoundsRect.Right) and (sc.Y > TWinControl(Components[i]).BoundsRect.Top) and (sc.Y < TWinControl(Components[i]).BoundsRect.Bottom) then result := TWinControl(Components[i]); end; end; end;
function TMyClass.GetMouseControl(AForm: TForm): TWinControl;
var
i: Integer;
sc: TPoint;
begin
result := nil;
with AForm do
begin
sc := ScreenToClient(Mouse.CursorPos);
for i := 0 to ComponentCount-1 do
begin
if AForm.Components[i] is TWinControl then
if (sc.X > TWinControl(Components[i]).BoundsRect.Left) and
(sc.X < TWinControl(Components[i]).BoundsRect.Right) and
(sc.Y > TWinControl(Components[i]).BoundsRect.Top) and
(sc.Y < TWinControl(Components[i]).BoundsRect.Bottom) then
result := TWinControl(Components[i]);
end;
end;
end;