My Environment: C++ Builder XE4
Is it possible for FormB to know FormB is shown with Show() or ShowModal()?
At FormA:
void __fastcall TFormA::Button1Click(TObject *Sender)
{
FormB->Show();
// FormB->ShowModal();
}
At FormB:
void __fastcall TFormB::FormShow(TObject *Sender)
{
// with some if sentence to know Show() or ShowModal()
}
You can test for fsModal in FormState
at the onShowEvent of your form.
I've made you a small example:
Create a new project, and add an extra form to it. On the Main Form place two buttons, and let them display your second form:
uses Unit2;
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.Show;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Form2.ShowModal;
end;
No magic here :D
Then add an OnShowEvent
to your Form2
:
procedure TForm2.FormShow(Sender: TObject);
begin
if fsModal in FormState then
Caption := 'ShowModal'
else
Caption := 'Show';
end;
That should do the trick for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With