RAD Studio VCL Reference
|
Provides runtime access to the header control's drawing surface.
property Canvas: TCanvas;
__property TCanvas Canvas;
The read-only Canvas property provides access to the header control's drawing surface that can be used when implementing a handler for the OnDrawSection event.
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) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|