Recent

Author Topic: [SOLVED] TPanels Top and Bottom  (Read 1111 times)

Pe3s

  • Hero Member
  • *****
  • Posts: 596
[SOLVED] TPanels Top and Bottom
« on: September 01, 2022, 08:25:48 pm »
Hello, I need to add a panel on the top, but then two panels are shown at once, not each panel separately, how can I solve it?

Code: Pascal  [Select][+][-]
  1. uses LCLIntf;
  2.  
  3. const
  4.   ControlPanelHeight = 40;
  5.   TopPanelHeight = 32;
  6.  
  7.  
  8. procedure TForm1.FormCreate(Sender: TObject);
  9. begin
  10.   pnControl.Height := 0;
  11. TopPanelHeight = 0;
  12. end;
  13.  
  14. procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  15.   Y: Integer);
  16. var
  17.   P: TPoint;
  18.   R: TRect;
  19. begin
  20.   R := TRect.Create(0, Self.Height - ControlPanelHeight, Self.Width, Self.Height);
  21.   P.X := X;
  22.   P.Y := Y;
  23.   if PtInRect(R, P) then
  24.     pnControl.Height := ControlPanelHeight
  25.   else
  26.     pnControl.Height := 0;
  27. end;
  28.  
  29. procedure TForm1.pnControlMouseLeave(Sender: TObject);
  30. begin
  31.   pnControl.Height := 0;
  32. end;
  33.  
« Last Edit: September 02, 2022, 07:01:44 pm by Pe3s »

paweld

  • Hero Member
  • *****
  • Posts: 1419
Re: TPanels Top and Bottom
« Reply #1 on: September 01, 2022, 09:10:08 pm »
I don't know if I understood correctly - you mean hiding Panel1 when pnControl is visible?
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin  
  3.   pnControl.Visible := False;
  4.   Panel1.Visible := True;
  5. end;
  6.  
  7. procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  8. var
  9.   R: TRect;
  10. begin
  11.   R := Rect(0, Height - pnControl.Height, Width, Height);
  12.   pnControl.Visible := R.Contains(Point(X, Y));
  13.   Panel1.Visible := not pnControl.Visible;
  14. end;
Best regards / Pozdrawiam
paweld

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TPanels Top and Bottom
« Reply #2 on: September 01, 2022, 09:11:28 pm »
If I have understood the behaviour you are after I think the attached project shows one way to achieve it.

Pe3s

  • Hero Member
  • *****
  • Posts: 596
Re: TPanels Top and Bottom
« Reply #3 on: September 01, 2022, 09:47:03 pm »
@ paweld it's about hiding two panels and showing each of them after hovering over the mouse and hiding them after taking the mouse

paweld

  • Hero Member
  • *****
  • Posts: 1419
Re: TPanels Top and Bottom
« Reply #4 on: September 01, 2022, 10:19:48 pm »
The solution was provided by @howardpc. But you can also do it like this
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   panel1.Visible := False;
  4.   pnControl.Visible := False;
  5. end;
  6.  
  7. procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  8. begin
  9.   panel1.Visible := panel1.BoundsRect.Contains(Point(X, Y));
  10.   pnControl.Visible := pnControl.BoundsRect.Contains(Point(X, Y));
  11. end;  
  12.  
Best regards / Pozdrawiam
paweld

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: TPanels Top and Bottom
« Reply #5 on: September 01, 2022, 10:49:28 pm »
Idk "the solution" but i would suggest to use Mouse Enter and Leave event.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

paweld

  • Hero Member
  • *****
  • Posts: 1419
Re: TPanels Top and Bottom
« Reply #6 on: September 02, 2022, 06:55:12 am »
if the panel is not visible then OnMouseEenter will not work
Best regards / Pozdrawiam
paweld

Pe3s

  • Hero Member
  • *****
  • Posts: 596
Re: TPanels Top and Bottom
« Reply #7 on: September 02, 2022, 06:40:54 pm »
Hi @paweld what do I have to correct in the code so that there is no error
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Image32MouseMove(Sender: TObject; Shift: TShiftState; X,
  2.   Y: Integer; Layer: TCustomLayer);
  3. begin
  4.   Toolbar.Visible := Toolbar.BoundsRect.Contains(Point(X, Y));
  5. end;
  6.  

 
Code: Pascal  [Select][+][-]
  1. unit1.pas(68,57) Fatal: Syntax error, ")" expected but "," found
  2.  

Pe3s

  • Hero Member
  • *****
  • Posts: 596
Re: TPanels Top and Bottom
« Reply #8 on: September 02, 2022, 07:01:23 pm »
Thank you for your help, great beer, gentlemen

 

TinyPortal © 2005-2018