Search code examples
delphic++buildervcl

How to activate a form that has a parent?


I am trying to achieve an interface similar to old versions of Access, which embeds forms inside forms inside forms.

Screenshot of old Access with forms inside forms

I have a form (Form1) and TPanel (Panel1) inside it. I created two other forms and said that their Parent=Panel1;

enter image description here

The problem is that I cannot activate Form2 (put her in front of Form3) unless I click its title bar. Clicking on the form itself has no effect, no even when dragging the form it will still be behind Form3, and I need when I click the form or drag it to automatically becomes "active", meaning in front of Form3.

How to do this? Both Delphi & C++ Builder solutions are acceptable.


Solution

  • While I agree with the rest about using MDI instead, in putting these forms in the panel you make them supplicant controls (and not forms). So you would need to listen to the Click event for each of those forms and then call BringToFront when you receive it.

    procedure TForm3.FormClick(Sender: TObject);
      begin
        BringToFront;
      end;
    

    I don't know how the event will work if you click on one of the controls of the form (whether the control event will fire instead) in such an environment, but doing this will produce the effect you're looking for.