捕获/创建TCustomControl Delphi的OnGetFocus / OnLostFocus事件

我创建了一个继承自TCustomControl的Delphi组件.该组件可以从TWinControl继承而成为焦点,但是当它聚焦时我需要“突出显示”并在失去焦点时更改某些属性.
正如Delphi文档所说,TCustomControl没有继承的OnFocus事件,所以我需要捕获事件(?)并实现我自己的OnGetFocus / OnLostFocus事件处理程序(?).
当组件获得/失去焦点时,如何捕获事件?

解决方法

控件接收或丢失输入焦点时触发的事件是 OnEnterOnExit,并从作为组件开发人员应覆盖的 DoEnterDoExit方法触发:

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;

相关文章

 从网上看到《Delphi API HOOK完全说明》这篇文章,基本上都...
  从网上看到《Delphi API HOOK完全说明》这篇文章,基本上...
ffmpeg 是一套强大的开源的多媒体库 一般都是用 c/c+&#x...
32位CPU所含有的寄存器有:4个数据寄存器(EAX、EBX、ECX和ED...
1 mov dst, src dst是目的操作数,src是源操作数,指令实现的...