捕获/创建TCustomControl Delphi的OnGetFocus/OnLostFocus事件
我创建了一个继承自TCustomControl的Delphi组件。该组件可以从TWinControl继承而来,但我需要在其获得焦点时“突出显示”,并在失去焦点时更改一些属性。 正如Delphi文档所述,TCustomControl没有继承的OnFocus事件,因此我需要捕获事件(?)并实现自己的OnGetFocus/OnLostFocus事件处理程序(?)。捕获/创建TCustomControl Delphi的OnGetFocus/OnLostFocus事件,delphi,events,focus,components,Delphi,Events,Focus,Components,我创建了一个继承自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:这应该作为答案而不是评论发布。