RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
THeaderSection.Style Property

Determines how the header section's text is displayed.

Pascal
property Style: THeaderSectionStyle;
C++
__property THeaderSectionStyle Style;

If Style is set to hsText (the default), the string contained in the Text property is displayed in the header section, using the alignment specified by Alignment. The font is determined by the header control's Font property. A graphic image can appear beside the text if the ImageIndex property is set. 

If Style is set to hsOwnerDraw, the content displayed in the header section is drawn at run time on the header control's canvas by code in an OnDrawSection event handler.  

C++ Examples: 

 

/*
Add a THeaderControl to the form and call 
HeaderControl1DrawSection for the OnDrawSection event.
*/
void __fastcall TForm1::HeaderControl1DrawSection(THeaderControl *HeaderControl,
      THeaderSection *Section, const TRect &Rect, bool Pressed)
{
  if (Pressed)
    HeaderControl->Canvas->Font->Color = clRed;
  else
    HeaderControl->Canvas->Font->Color = clBlue;
  HeaderControl->Canvas->TextOut(Rect.Left + HeaderControl->Canvas->Font->Size, Rect.Top + 2, "Custom " + IntToStr(Section->Index));
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  THeaderSection *Section;
  for (int i = 0; i <= 4; i++)
  {
    Section = HeaderControl1->Sections->Add();
    Section->Text = "Section " + IntToStr(i);
    Section->MinWidth =
      (Section->Text).Length() *
      HeaderControl1->Font->Size;
    // Owner draw every other section
    if (i % 2 == 0)
      Section->Style = hsOwnerDraw;
    else
      Section->Style = hsText;
  }
}

 

Delphi Examples: 

{
Add a THeaderControl to the form and call 
HeaderControl1DrawSection for the OnDrawSection event.
}
procedure TForm1.FormCreate(Sender: TObject);
var
  HeaderSection: THeaderSection;
  I: Integer;
begin
  for I := 0 to 4 do
  begin
    HeaderSection := HeaderControl1.Sections.Add;
    HeaderSection.Text := 'Text Section ' + IntToStr(I);
    HeaderSection.MinWidth := length(HeaderSection.Text) * Font.Size;
    // Owner draw every other section
    if (I mod 2 = 0) then
      HeaderSection.Style := hsOwnerDraw
    else
      HeaderSection.Style := hsText;
  end;
end;

procedure TForm1.HeaderControl1DrawSection(HeaderControl: THeaderControl;
  Section: THeaderSection; const Rect: TRect; Pressed: Boolean);
begin
  with HeaderControl.Canvas do
  begin
    // highlight pressed sections
    if Pressed then
      Font.Color := clRed
    else
      Font.Color := clBlue;
    TextOut(Rect.Left + Font.Size, Rect.Top + 2, 'Owner Drawn text');
  end;
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!