我现在用控件数组用程序实现放很多panel在窗体中,现在想让鼠标在具体某个Panel时,能提示该Panel的提示.即显示Hint.该怎么实现?我主要的困惑是怎么根据鼠标的位置来判断它在哪个Panel上?

解决方案 »

  1.   

    写需要的某个panel的OnMouseMove事件
      

  2.   

    可是刚开始我怎么知道是哪个Panel呢?怎么写?
      

  3.   

    这个简单,比如说有3个panel,先写好各个panel的hint属性,然后在各个panel的onmouseup事件中分别输入panel1.showhint:=true;panel3.showhint:=true;panel3.showhint:=true;即可。
      

  4.   

    当鼠标移到时panel的hint属性就显示。
      

  5.   

    既然都已经用了控件数组了就用循环摄制每一个panel的hint所有的Panel都是用同一个OnMouseMove(给一个index参数),这样还有什么问题吗
      

  6.   

    得到窗体鼠标下面的控件
    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;