如何在鼠标移动时显示面板?德尔福

时间:2011-03-17 09:50:16

标签: delphi mouse visible

当我将鼠标移动到其位置时,如何使面板显示其中的所有内容?

当我再次将其移开时,它会逐渐消失?

在可见时执行此操作不是问题(淡出除外),我可以使用onmouseleaves执行此操作。

但是当它不可见时你如何让它可见?

thankssss

2 个答案:

答案 0 :(得分:4)

将面板放在另一个(空白)面板上。当鼠标移动到空白面板上时,显示“魔术”面板。


编辑,因为我现在已经了解了OP在WebBrowser上有Panel。我放置假/空白面板的解决方案不再有效;干扰发往WebBrowser的鼠标消息也不是一个好主意,所以这里有一个简单的方法来解决这个问题。我正在使用一个TTimer,它的间隔设置为“100”,我正在汇集鼠标坐标。

procedure TForm25.Timer1Timer(Sender: TObject);
var PR: TRect; // Panel Rect (in screen coordinates)
    CP: TPoint; // Cursor Position (always in screen coordinates)
begin
  // Get the panel's coordinates and convert them to Screen coordinates.
  PR.TopLeft := Panel1.ClientToScreen(Panel1.ClientRect.TopLeft);
  PR.BottomRight := Panel1.ClientToScreen(Panel1.ClientRect.BottomRight);
  // Get the mouse cursor position
  CP := Mouse.CursorPos;
  // Is the cursor over the panel?
  if (CP.X >= PR.Left) and (CP.X <= PR.Right) and (CP.Y >= PR.Top) and (CP.Y <= PR.Bottom) then
    begin
      // Panel should be made visible
      Panel1.Visible := True;
    end
  else
    begin
      // Panel should be hidden
      Panel1.Visible := False;
    end;
end;

答案 1 :(得分:1)

如果您的面板将出现在您的面板中,您可以捕获底层表单或父面板的鼠标移动事件,并检查它是否在您的不可见面板将出现的范围内。

例如。 (伪代码)

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if ((X > MyPanel.Left) and (Y > MyPanel.Top) and (X < mypanel.right) and 
  (Y < mypanel.bottom)) then
  begin
      mypanel.visible := true;
  end;
end;