RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TScreen.OnActiveFormChange Event

Occurs immediately after a new form becomes active in a multi-form application.

Pascal
property OnActiveFormChange: TNotifyEvent;
C++
__property TNotifyEvent OnActiveFormChange;

Write an OnActiveFormChange event handler to take specific action when a new form becomes active. OnActiveFormChange occurs when the active form for the application changes, not when a form becomes active because the application becomes active.  

C++ Examples: 

 

/*
This example uses two forms with a button on the first
form. When the user clicks the button, the second form
appears. As the user switches between forms, the form that
is active is colored aqua.
Note:   You must include the unit header for form 2 to the
unit file for form 1, and add the public ColorForm method
to the definition of the TForm1 class.
*/
#include "Unit2.h"

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Form2->Show();
}

void __fastcall TForm1::ColorForm(TObject *Sender)
{
  Color = clWhite;
  Form2->Color = clWhite;
  Screen->ActiveForm->Color = clAqua;
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  Screen->OnActiveFormChange = ColorForm;
}

void __fastcall TForm1::FormDestroy(TObject *Sender)
{
  // This stops ColorForm from being called during termination.
  Screen->OnActiveFormChange = NULL;
}

 

Delphi Examples: 

{
This example uses a two forms with a button on the first
form. When the user clicks the button, the second form
appears. As the user switches between forms, the form that
is active is colored aqua.
Note:   You must include the unit header for form 2 to the
unit file for form 1, and add the public ColorForm method
to the header for form 1’s unit.
}
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    procedure ColorForm(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses Unit2;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.Show;
end;

procedure TForm1.ColorForm(Sender: TObject);
begin
  Color := clWhite;
  Form2.Color := clWhite;
  Screen.ActiveForm.Color := clAqua;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
  Screen.OnActiveFormChange := ColorForm;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  // This stops ColorForm from being called during termination.
  Screen.OnActiveFormChange := nil;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!