OnActiveFormChange (C++)
Description
This example uses two forms with a button on the first form. When you click the button, the second form appears. As you switch between forms, the form that is active is colored aqua. Note: You must include the unit header for the second form to the unit file for the first form and add the public ColorForm method to the definition of the TForm1 class.
Code
#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;
}
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Screen->OnActiveFormChange = ColorForm;
}
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
// This stops ColorForm from being called during termination.
Screen->OnActiveFormChange = NULL;
}
Uses
- Vcl.Forms.TScreen.ActiveForm ( fr | de | ja )
- Vcl.Forms.TScreen.OnActiveFormChange ( fr | de | ja )