Board index » delphi » focus of a TWinControl

focus of a TWinControl


2003-11-04 05:17:23 PM
delphi92
hi folks,
Currently I write my first component that should receive key-press-events
(not the my first component in generel).
My problem is, that this component (an direct descendend of TCustomControl)
does not receive any key-press-message from the system, unless i set the
focus to the component explitcitly (with MyComponent.SetFocus).
The component does not get the focus by clicking on it.
What to do ?
Is there a given way to solve that problem ?
Should I send a message WM_SETFOCUS to my control and WM_KILLFOCUS to the
focused whenever I want the focus ?
thanks in advance
Steffen
 
 

Re:focus of a TWinControl

On Tue, 4 Nov 2003 10:17:23 +0100, Steffen
Klössel<XXXX@XXXXX.COM>said ...
Quote
Currently I write my first component that should receive key-press-events
(not the my first component in generel).
My problem is, that this component (an direct descendend of TCustomControl)
does not receive any key-press-message from the system, unless i set the
focus to the component explitcitly (with MyComponent.SetFocus).
The component does not get the focus by clicking on it.
Can you show us the code for your component?
Marc
 

Re:focus of a TWinControl

"Steffen Klössel" <XXXX@XXXXX.COM>writes:
Quote
My problem is, that this component (an direct descendend of TCustomControl)
does not receive any key-press-message from the system, unless i set the
focus to the component explitcitly (with MyComponent.SetFocus).
Unless the component has the focus, it will never get key messages, of
course.
Quote
The component does not get the focus by clicking on it.
Correct. No where in Windows or the VCL do they actually do that for
you. You would think it was perfectly obvious that it would be
automatic.
Quote
What to do ?
Give your component a WMLButtonDown (right and middle buttons too if
desired) method and in there write:
inherited;
SetFocus;
Good luck.
Kurt
 

Re:focus of a TWinControl

thank you ..
that was the answere I needed
Steffen
"Kurt Barthelmess (TeamB)" <XXXX@XXXXX.COM>schrieb im
Newsbeitrag news:XXXX@XXXXX.COM...
Quote
"Steffen Klössel" <XXXX@XXXXX.COM>writes:

>My problem is, that this component (an direct descendend of
TCustomControl)
>does not receive any key-press-message from the system, unless i set the
>focus to the component explitcitly (with MyComponent.SetFocus).

Unless the component has the focus, it will never get key messages, of
course.

>The component does not get the focus by clicking on it.

Correct. No where in Windows or the VCL do they actually do that for
you. You would think it was perfectly obvious that it would be
automatic.

>What to do ?

Give your component a WMLButtonDown (right and middle buttons too if
desired) method and in there write:

inherited;
SetFocus;

Good luck.

Kurt