Recent

Author Topic: Component shouldn't lose focus when tab is pressed  (Read 5988 times)

Yakumo500

  • New Member
  • *
  • Posts: 30
Component shouldn't lose focus when tab is pressed
« on: November 18, 2010, 07:16:58 pm »
Hi,
currently I'm writing an editor component and I have a problem with the tab key.
It's recognized by KeyDown but my control will lose focus. How could I change that?

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Component shouldn't lose focus when tab is pressed
« Reply #1 on: November 18, 2010, 07:23:52 pm »
Your component is a descendant of what?

SetFocus should be sufficient.
« Last Edit: November 18, 2010, 07:26:21 pm by typo »

Yakumo500

  • New Member
  • *
  • Posts: 30
Re: Component shouldn't lose focus when tab is pressed
« Reply #2 on: November 18, 2010, 07:31:00 pm »
It's a descendant of TCustomControl.

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Component shouldn't lose focus when tab is pressed
« Reply #3 on: November 18, 2010, 07:39:08 pm »
SetFocus can restore the focus to your control.

Yakumo500

  • New Member
  • *
  • Posts: 30
Re: Component shouldn't lose focus when tab is pressed
« Reply #4 on: November 18, 2010, 07:49:51 pm »
But if I write SetFocus in Keydown or Keypress or Keyup nothing happens. I think the focus change happens after Keydown and Keypress and Keyup are executed.

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Component shouldn't lose focus when tab is pressed
« Reply #5 on: November 18, 2010, 08:00:47 pm »
Have you tried to set Key := #0 on the KeyPress event or Key := 0 on the KeyDown event?

Code: [Select]
procedure TYourControl.ComponentKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  // uses Windows unit
  if Key = VK_TAB then
    Key := 0;
end;
« Last Edit: November 19, 2010, 04:50:41 pm by typo »

Yakumo500

  • New Member
  • *
  • Posts: 30
Re: Component shouldn't lose focus when tab is pressed
« Reply #6 on: November 19, 2010, 04:19:09 pm »
Oh
it's so easy and I didn't get it. Thank you.

 

TinyPortal © 2005-2018