如何让鼠标移到面板上时出现面板?德尔菲

发布于 2024-10-24 03:13:51 字数 157 浏览 5 评论 0原文

当我将鼠标移到某个位置时,如何才能显示一个面板及其中的所有内容?

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

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

但是当它不可见时,如何使其可见呢?

谢谢

How can I make a panel appear with everything that is in it when I move my mouse over its location?

When I move it off again, it fades back out?

Doing it when it is visible is not a problem (except the fading out), I can do this with onmouseleaves.

But when it is invisible how do you make it visible?

thankssss

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赠佳期 2024-10-31 03:13:51

将面板放在另一个(空白)面板上。当您将鼠标移动到空白面板上时,使“神奇”面板显示出来。


编辑,因为我现在了解到 OP 在网络浏览器上有面板。我放置虚拟/空白面板的解决方案不再有效;干扰发送到 Web 浏览器的鼠标消息也不是一个好主意,因此这里有一个简单的方法来解决此问题。我正在使用 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;

Put the panel on another (blank) panel. Make the "magic" panel show up when you get mouse movement over the blank panel.


Edited, because I now learned the OP has the Panel over a WebBrowser. My solution of placing an dummy / blank panel no longer works; Interfering with mouse messages going to the WebBrowser is also not a good idea, so here's a simple way to fix this. I'm using an TTimer with it's interval set to "100" and I'm pooling the mouse coordinates.

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;
溺深海 2024-10-31 03:13:51

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

。 (伪代码)

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;

If you have an area that your panel will appear in, you can capture the mouse move event for the underlying form or parent panel and check it is within the bounds that your invisible panel will appear in.

eg. (pseudocode)

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文