首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为TCustomControl Delphi捕获/创建OnGetFocus/OnLostFocus事件

为TCustomControl Delphi捕获/创建OnGetFocus/OnLostFocus事件
EN

Stack Overflow用户
提问于 2015-06-28 16:47:25
回答 1查看 2.6K关注 0票数 8

我创建了一个从TCustomControl继承的Delphi组件。组件可以像从TWinControl继承的那样获得焦点,但是当它的焦点变得集中时,我需要“突出显示”,当它失去焦点时,我需要更改一些属性。正如德尔菲文档所述,TCustomControl没有继承的OnFocus事件,所以我需要捕获事件(?)并实现我自己的OnGetFocus/OnLostFocus事件处理程序(?)。当组件获得/失去焦点时,如何捕获事件?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-01 08:07:28

控件接收或丢失输入焦点时触发的事件是OnEnterOnExit,这些事件来自您作为组件开发人员应该重写的DoEnterDoExit方法:

代码语言:javascript
运行
复制
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;
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31102263

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档