我创建了一个从TCustomControl继承的Delphi组件。组件可以像从TWinControl继承的那样获得焦点,但是当它的焦点变得集中时,我需要“突出显示”,当它失去焦点时,我需要更改一些属性。正如德尔菲文档所述,TCustomControl没有继承的OnFocus事件,所以我需要捕获事件(?)并实现我自己的OnGetFocus/OnLostFocus事件处理程序(?)。当组件获得/失去焦点时,如何捕获事件?
发布于 2015-07-01 08:07:28
控件接收或丢失输入焦点时触发的事件是OnEnter和OnExit,这些事件来自您作为组件开发人员应该重写的DoEnter和DoExit方法:
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;https://stackoverflow.com/questions/31102263
复制相似问题