例如 在IMAGE1上 就如何如何……在MEMO1上就如何如何……在DBGRID1上 就如何如何……有什么好方法吗??关键是判断 鼠标所在的区域 属于哪个组件

解决方案 »

  1.   

    好像很多可视化的控件都有onmousemove事件
      

  2.   

    function ControlFromPoint(mParent: TWinControl; mPoint: TPoint;
      mExcludeContols: array of TControl): TControl;
    var
      I: Integer;
      J: Integer;
      B: Boolean;
    begin
      Result := nil;
      if not Assigned(mParent) then Exit;
      for I := mParent.ControlCount - 1 downto 0 do begin
        B := False;
        for J := Low(mExcludeContols) to High(mExcludeContols) do
          if mParent.Controls[I] = mExcludeContols[J] then begin
            B := True;
            Break;
          end;
        if B then Continue;    if PtInRect(mParent.Controls[I].BoundsRect, mPoint) then begin
          if not mParent.Controls[I].Visible then Continue;
          if mParent.Controls[I] is TWinControl then
            Result := ControlFromPoint(TWinControl(mParent.Controls[I]),
              Point(mPoint.X - mParent.Controls[I].Left,
                mPoint.Y - mParent.Controls[I].Top), mExcludeContols);
          if not Assigned(Result) then Result := mParent.Controls[I];
          Break;
        end;
      end;
    end; { ControlFromPoint }procedure TForm1.Timer1Timer(Sender: TObject);
    var
      vControl: TControl;
    begin
      vControl := ControlFromPoint(Self, ScreenToClient(Mouse.CursorPos), []);
    (*
      vControl := ControlAtPos(ScreenToClient(Mouse.CursorPos), True, True);
      //系统方法TWinControl.ControlAtPos()但不支持子控件
    *)
      if Assigned(vControl) then
        Caption := vControl.Name
      else Caption := '<nil>';
    end;