PopulateTabSheets (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This examples requires a TPageControl and a TCheckBox. The form OnCreate event handler populates each sheet with an edit control placed somewhere on the client area of the sheet. Unchecking the checkbox causes the client area (not the tab area) of the Tab Control to become invisible.

Code

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  PageControl1.ActivePage.Visible := CheckBox1.Checked;
end;

procedure TForm1.PageControl1Change(Sender: TObject);
begin
  CheckBox1.Checked := PageControl1.ActivePage.Visible;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  for i := 0 to 9 do
    with TTabSheet.Create(Self) do
    begin
      PageControl := PageControl1;
      Caption := 'TabSheet' + IntToStr(i);
      with TEdit.Create(Self) do
      begin
        Parent := PageControl1.Pages[i];
        Left := Random(PageControl1.ActivePage.ClientWidth - Width);
        Top := Random(PageControl1.ActivePage.ClientHeight - Height);
      end;
    end;
    PageControl1Change(Sender);
end;

Uses

Personal tools
Assistance