I created a Delphi component inherited from TCustomControl. The component can get focused as inherited from TWinControl, but I need to "highlight" when its get focused and change some properties when it loses the focus. As the Delphi documentation says, TCustomControl have no inherited OnFocus event, so I need to catch the event(?) and implement my own OnGetFocus/OnLostFocus event handlers(?). How can I catch the events when the component get/lose the focus?
The events fired when the control receives or loses the input focus are OnEnter
and OnExit
and are fired from the DoEnter
and DoExit
methods which you as a component developer should override:
type
TMyControl = class(TCustomControl)
protected
procedure DoEnter; override;
procedure DoExit; override;
end;
implementation
{ TMyControl }
procedure TMyControl.DoEnter;
begin
inherited;
// the control received the input focus, so do what you need here; note
// that it's recommended to call inherited inside this method (which as
// described in the reference should only fire the OnEnter event now)
end;
procedure TMyControl.DoExit;
begin
inherited;
// the control has lost the input focus, so do what you need here; note
// that it's recommended to call inherited inside this method (which as
// described in the reference should only fire the OnExit event now)
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With