开发者

How to make a panel appear when the mouse moves over it? delphi

开发者 https://www.devze.com 2023-02-17 14:42 出处:网络
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?

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 开发者_StackOverflowmake it visible?

thankssss


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;


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消