Board index » cppbuilder » PageControl - creation of new pages at runtime

PageControl - creation of new pages at runtime

Hi,

My plan is to handle a TPageControl object so that more pages could be
added during runtime, for instance via a button (or anything). The pages
should all be in a standard format, e.g. with Edit, Labels, TChart
components, i.e. the pages should be created using some sort of a template,
defining each of the "page objects".

I hope I made my intentions clear.

So how do I start?

regards,
S{*word*249} Z. Dyrmose
Denmark

 

Re:PageControl - creation of new pages at runtime


Quote
> more pages could be added during runtime

This should get you started:

void __fastcall TForm1::Button1Click(TObject *)
{
   // Create a new page in PageControl1
   TTabSheet *Page = new TTabSheet(this);
   Page->PageControl = PageControl1;
   Page->Caption = "Test Page";

   // Add an edit box to this page
   TEdit *Edit = new TEdit(this);
   Edit->Parent = Page;
   Edit->Top = 10;
   Edit->Left = 10;

Quote
}

--
Yoto Yotov

Re:PageControl - creation of new pages at runtime


Quote
S{*word*249} Z. Dyrmose wrote:
> My plan is to handle a TPageControl object so that more pages
> could be added during runtime, for instance via a button (or anything).
> The pages > should all be in a standard format, e.g. with Edit, Labels,
> TChart components, i.e. the pages should be created using some sort
> of a template, defining each of the "page objects".

You can create a form with the dimensions of your TPageControl::
ClientRect, setting the form's BorderStyle to bsNone, and placing all
your controls on the form visually.  Each time you want to add a page
to your TPageControl, create a new TTabsheet, setting the PageControl
property to your TPageControl.  Then create a new form and set it's
parent to your newly created TTabSheet.  Be sure to set the form's top
and left properties to zero so it will be visible in the TTabSheet and not
clipped.  This way, you will not have to keep pointers to multiple
dynamically created components but only to the re-parented forms.
Maybe you could store pointers to the forms in the Tag property of the
TTabSheet or possibly keep them in a vector class to avoid all that {*word*193}
casting...

Other Threads