Lazarus

Programming => General => Topic started by: Gald on October 24, 2020, 07:05:26 pm

Title: About using Panel as Button [SOLVED]
Post by: Gald 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?
Title: Re: About using Panel as Button
Post by: jamie on October 24, 2020, 07:16:44 pm
try setfocus

Title: Re: About using Panel as Button
Post by: Blaazen 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.
Title: Re: About using Panel as Button
Post by: speter 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.

Title: Re: About using Panel as Button
Post by: Gald on October 25, 2020, 01:57:47 am
Thank you all!  :D
TinyPortal © 2005-2018