开发者

How to find previous active control: Delphi

I want to get the previous active control in Delphi, i hav开发者_JAVA技巧e tried to used OnActiveControlChange event, but even through that i can get the current active control not the previous one.

Thanks for the help in advance. --Vijay


Try this Code

  TForm1 = class(TForm)
  ---
  --- 
  private
    { Private declarations }
    wcActive, wcPrevious : TWinControl;
  public
    { Public declarations }
    procedure ActiveControlChanged(Sender: TObject) ;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ActiveControlChanged(Sender: TObject);
begin
  wcPrevious := wcActive;
  wcActive := Form1.ActiveControl;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Screen.OnActiveControlChange := ActiveControlChanged;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Screen.OnActiveControlChange := nil;
end;

Use wcControl.Name to get the name of previous control

For more information go through this link


You could build yourself a 'history' of active controls using this event, and to find the previous you would consult your history list.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜