HeaderControlSection (C++)

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

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  // 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
  THeaderSection *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;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckBox1Click(TObject *Sender)
{
  HeaderControl1->NoSizing = !CheckBox1->Checked;
  HeaderControl1->CheckBoxes = CheckBox1->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::HeaderControl1SectionCheck(TCustomHeaderControl *HeaderControl,
          THeaderSection *Section)
{
  Section->FixedWidth = Section->Checked;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::HeaderControl1SectionClick(THeaderControl *HeaderControl,
          THeaderSection *Section)
{
  if (HeaderControl1->NoSizing == false)
  {
    Section->CheckBox = !Section->CheckBox;
    Section->Checked = false;
  }
}
//---------------------------------------------------------------------------

Uses