Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FireMonkey: How to focus the next control on vkReturn?

Classic VCL question... but how to do the same within FireMonkey?

I have several standard TControl who can focus...

For instance, in some TEdit, I want to move to the next focusable control if I press the return key

I have try different approach but without success (replacing the key, keychar with 9 when it's 13, ..., forwarding the key events to the form, ...)

Of course, as it is FMX, I'd like a solution which works on all platforms...

If it can avoid to:

  • browse the Children property of the parents,
  • have different pieces of code to address the different platforms
  • hard-code the tab sequence
  • ..., it will be great ;o)
like image 354
Whiler Avatar asked Dec 26 '22 15:12

Whiler


1 Answers

You can place the following code into the OnKeyDown event of the form:

  if Key = vkReturn then begin
    Key := vkTab;
    KeyDown(Key, KeyChar, Shift);   
  end;

If you want that behaviour only for some of the controls, you must call this code in the OnKeyDown events of those controls.

Be aware that the KeyDown must call the TForm.KeyDown to make it work.

(Tested with XE2)

like image 115
Uwe Raabe Avatar answered Dec 31 '22 12:12

Uwe Raabe