Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
VCL graphics code snippet to get a TForm in a TForm. In other words: to use a TForm as a TPanel.
You can
* View the code below
* Download the code of ProjectTFormInTForm (zip).
* View a screenshot of ProjectTFormInTForm (png)
Make sure that FormChild is not an auto-created form (do Project | Options | Forms and put FormChild in the Available forms list).
//---------------------------------------------------------------------------
/*
ProjectTFormInTForm, demonstration to put a TForm in a TForm
Copyright (C) 2009 Richel Bilderbeek
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFormParentH
#define UnitFormParentH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
#include <boost/shared_ptr.hpp>
//---------------------------------------------------------------------------
class TFormParent : public TForm
{
__published: // IDE-managed Components
TPanel *PanelBottom;
TPanel *PanelTop;
TPanel *PanelTopLeft;
TPanel *PanelBottomLeft;
TPanel *PanelTopRight;
TPanel *PanelBottomRight;
private: // User declarations
public: // User declarations
__fastcall TFormParent(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormParent *FormParent;
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
/*
ProjectTFormInTForm, demonstration to put a TForm in a TForm
Copyright (C) 2009 Richel Bilderbeek
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "UnitFormParent.h"
#include "UnitFormChild.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormParent *FormParent;
//---------------------------------------------------------------------------
__fastcall TFormParent::TFormParent(TComponent* Owner)
: TForm(Owner)
{
{
TFormChild * child = new TFormChild(this,"1");
assert(child->BorderStyle == bsNone);
child->Parent = PanelTopLeft;
child->Align = alClient;
child->Show();
}
{
TFormChild * child = new TFormChild(this,"2");
assert(child->BorderStyle == bsNone);
child->Parent = PanelTopRight;
child->Align = alClient;
child->Show();
}
{
TFormChild * child = new TFormChild(this,"3");
assert(child->BorderStyle == bsNone);
child->Parent = PanelBottomLeft;
child->Align = alClient;
child->Show();
}
{
TFormChild * child = new TFormChild(this,"4");
assert(child->BorderStyle == bsNone);
child->Parent = PanelBottomRight;
child->Align = alClient;
child->Show();
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
/*
ProjectTFormInTForm, demonstration to put a TForm in a TForm
Copyright (C) 2009 Richel Bilderbeek
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFormChildH
#define UnitFormChildH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TFormChild : public TForm
{
__published: // IDE-managed Components
TPanel *Panel;
private: // User declarations
public: // User declarations
__fastcall TFormChild(TComponent* Owner, const String& s);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormChild *FormChild;
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
/*
ProjectTFormInTForm, demonstration to put a TForm in a TForm
Copyright (C) 2009 Richel Bilderbeek
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "UnitFormChild.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormChild *FormChild;
//---------------------------------------------------------------------------
__fastcall TFormChild::TFormChild(TComponent* Owner, const String& s)
: TForm(Owner)
{
Panel->Caption = "Child #" + s;
}
//---------------------------------------------------------------------------
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.