Recent

Author Topic: About using Panel as Button [SOLVED]  (Read 637 times)

Gald

  • Full Member
  • ***
  • Posts: 107
About using Panel as Button [SOLVED]
« on: October 24, 2020, 07:05:26 pm »
Hello!
Im trying to use Panel as Button, but there are a few problems with that.

I know, Panel can receive focus by the code: "Panel1.TabStop := True".

But how to simulate an event like "onGetFocus and OnLoseFocus" for doing some changes on appearance and also to receive keyboard actions like [Enter] and [Space] to activate their onClick event?
« Last Edit: October 25, 2020, 01:58:15 am by Gald »
Lazarus 2.0.12 r64642 FPC 3.2.0 x86_64-win64-win32/win64/Manjaro KDE 21
AMD Ryzen 3 1300X Quad-Core Processor 3.50 GHz / 8,00 GB RAM / GTX 1500 TI / 2TB M.2 NVMe

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: About using Panel as Button
« Reply #1 on: October 24, 2020, 07:16:44 pm »
try setfocus

The only true wisdom is knowing you know nothing

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: About using Panel as Button
« Reply #2 on: October 24, 2020, 07:18:50 pm »
Events you are looking for are OnEnter and OnExit. TPanel has key events, but they are not published, you have to assign them by code.
Code: Pascal  [Select][+][-]
  1. Panel1.OnKeyDown:=@MyKeyDown;
MyKeyDown must be TKeyEvent with proper parameters.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

speter

  • Sr. Member
  • ****
  • Posts: 337
Re: About using Panel as Button
« Reply #3 on: October 25, 2020, 01:13:12 am »
Also, you may need to set
 (form).keypreview := true;
either at design or runtime; this is needed to receive keyboard events for the [enter] key etc.

cheers
S.

I climbed mighty mountains, and saw that they were actually tiny foothills. :)

Gald

  • Full Member
  • ***
  • Posts: 107
Re: About using Panel as Button
« Reply #4 on: October 25, 2020, 01:57:47 am »
Thank you all!  :D
Lazarus 2.0.12 r64642 FPC 3.2.0 x86_64-win64-win32/win64/Manjaro KDE 21
AMD Ryzen 3 1300X Quad-Core Processor 3.50 GHz / 8,00 GB RAM / GTX 1500 TI / 2TB M.2 NVMe

 

TinyPortal © 2005-2018