Recent

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

Gald

  • New Member
  • *
  • Posts: 12
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 »

jamie

  • Hero Member
  • *****
  • Posts: 3791
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: 2994
  • 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.1.0 r64115 FPC 3.3.1 r40507 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

  • New Member
  • *
  • Posts: 40
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.


Gald

  • New Member
  • *
  • Posts: 12
Re: About using Panel as Button
« Reply #4 on: October 25, 2020, 01:57:47 am »
Thank you all!  :D

 

TinyPortal © 2005-2018