Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
捕获/创建TCustomControl Delphi的OnGetFocus/OnLostFocus事件_Delphi_Events_Focus_Components - Fatal编程技术网

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

捕获/创建TCustomControl Delphi的OnGetFocus/OnLostFocus事件,delphi,events,focus,components,Delphi,Events,Focus,Components,我创建了一个继承自TCustomControl的Delphi组件。该组件可以从TWinControl继承而来,但我需要在其获得焦点时“突出显示”,并在失去焦点时更改一些属性。 正如Delphi文档所述,TCustomControl没有继承的OnFocus事件,因此我需要捕获事件(?)并实现自己的OnGetFocus/OnLostFocus事件处理程序(?)。 当组件获得/失去焦点时,如何捕捉事件 控件接收或丢失输入焦点时激发的事件是和,并且是从和方法激发的,作为组件开发人员,您应该覆盖这些和方法

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

控件接收或丢失输入焦点时激发的事件是和,并且是从和方法激发的,作为组件开发人员,您应该覆盖这些和方法:

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;

重写
DoEnter
DoExit
方法。非常感谢mutch@TLama,这正是我想要的for@TLama:这应该作为答案而不是评论发布。