HeaderControlSection (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This application requires a THeaderControl and a TCheckBox already on the form. If the sections are resizable, click on the header sections to display a checkbox next to their caption. Check a header control's checkbox to fix its width, so that it cannot be resized. Uncheck the checkbox to make it resizable again. This example shows how to use some of the new Vista features in the THeaderControl and THeaderSection classes.

Code

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  HeaderControl1.NoSizing := not CheckBox1.Checked;
  HeaderControl1.CheckBoxes := CheckBox1.Checked;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  Section: THeaderSection;
begin
  // center the form on the screen and change its size
  Form1.Position := poScreenCenter;
  Form1.Width := 400;
  Form1.Height := 200;

  // customize the check box
  CheckBox1.Left := 16;
  CheckBox1.Top := 40;
  CheckBox1.Width := 150;
  CheckBox1.Caption := 'Sections can be resized';
  CheckBox1.Checked := True;

  // allow the use of checkboxes in each section
  HeaderControl1.CheckBoxes := True;

  // create each section in the header control
  Section := HeaderControl1.Sections.Add;
  Section.Width := 100;
  Section.Text := 'English';
  Section.AllowClick := True;

  Section := HeaderControl1.Sections.Add;
  Section.Width := 100;
  Section.Text := 'Spanish';
  Section.AllowClick := True;

  Section := HeaderControl1.Sections.Add;
  Section.Width := 100;
  Section.Text := 'Portuguese';
  Section.AllowClick := True;
end;

procedure TForm1.HeaderControl1SectionCheck(HeaderControl: TCustomHeaderControl;
  Section: THeaderSection);
begin
  Section.FixedWidth := Section.Checked;
end;

procedure TForm1.HeaderControl1SectionClick(HeaderControl: THeaderControl;
  Section: THeaderSection);
begin
  if HeaderControl1.NoSizing = False then
  begin
    Section.CheckBox := not Section.CheckBox;
    Section.Checked := False;
  end;
end;

Uses

Personal tools
Assistance