unit HeaderListBox;
interface
uses
SysUtils, Classes, Controls, StdCtrls, Types, Windows, Graphics, ComCtrls;
type
TSettings =
class(TPersistent)
private
{ Private-Deklarationen }
FHeaderCount: Byte;
FTextColor : TColor;
FFrameColor : TColor;
procedure SetHeaderCount(Value : Byte);
procedure SetTextColor (Value : TColor);
procedure SetFrameColor (Value : TColor);
protected
{ Protected-Deklarationen }
public
{ Public-Deklarationen }
Constructor create;
published
{ Published-Deklarationen }
property HeaderCount : Byte
read FHeaderCount
write SetHeaderCount
default 2;
property TextColor : TColor
read FTextColor
write SetTextColor
default clBlack;
property FrameColor : TColor
read FFrameColor
write SetFrameColor
default clWhite;
end;
THeaderListBox =
class(TListBox)
private
{ Private-Deklarationen }
FSettings : TSettings;
FHeaderControl : THeaderControl;
protected
{ Protected-Deklarationen }
public
{ Public-Deklarationen }
constructor Create(AOwner:TComponent);
override;
destructor Destroy;
override;
procedure Loaded;
override;
procedure CreateWnd;
override;
published
{ Published-Deklarationen }
property Settings : TSettings
read FSettings
write FSettings;
end;
{ ---------------------------------------------------------------------------- }
procedure Register;
{ ---------------------------------------------------------------------------- }
implementation
{ ---------------------------------------------------------------------------- }
procedure Register;
begin
RegisterComponents('
Test', [THeaderListBox]);
end;
{ ---------------------------------------------------------------------------- }
{ THeaderListBox }
{ ---------------------------------------------------------------------------- }
constructor THeaderListBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Self.Left := 248;
Self.Width := 249;
Self.Height := 185;
Self.Top := 100;
Self.Style := lbOwnerDrawFixed;
Self.OnDrawItem := DrawAllItem;
FSettings := TSettings.Create;
if ComponentState = [csDesigning]
then Exit;
end;
{ ---------------------------------------------------------------------------- }
procedure THeaderListBox.CreateWnd;
var
i : Integer;
HS: THeaderSection;
begin
inherited;
FHeaderControl := THeaderControl.Create(Self);
FHeaderControl.Parent := Self.Parent;
FHeaderControl.Align := alCustom;
FHeaderControl.Left := 248;
FHeaderControl.Width := 249;
FHeaderControl.Height := 20;
FHeaderControl.Top := 81;
FHeaderControl.Style := hsButtons;
FHeaderControl.Show;
FHeaderControl.OnSectionResize := SectionResize;
if Assigned(Settings)
then
begin
for i := 0
to Settings.HeaderCount
do
begin
with FHeaderControl
do
begin
HS := Sections.Add;
HS.Text := '
Item' + IntToStr(i);
HS.Width := Width
div Settings.HeaderCount;
end;
end;
FHeaderControl.Invalidate;
end;
end;
{ ---------------------------------------------------------------------------- }
destructor THeaderListBox.Destroy;
begin
if Assigned(FSettings)
then
FSettings.Free;
inherited;
end;
{ ---------------------------------------------------------------------------- }
procedure THeaderListBox.Loaded;
begin
inherited Loaded;
if ComponentState = [csDesigning]
then Exit;
end;
{ ---------------------------------------------------------------------------- }
{ TSettings }
{ ---------------------------------------------------------------------------- }
constructor TSettings.create;
begin
inherited Create;
TextColor := clBlack;
FrameColor := clWhite;
FHeaderCount := 2;
end;
{ ---------------------------------------------------------------------------- }
procedure TSettings.SetHeaderCount(Value: Byte);
begin
if Value <> FHeaderCount
then
begin
FHeaderCount := Value;
//Invalidate; <--- Aktualisieren der ListBox!!!
end;
end;
{ ---------------------------------------------------------------------------- }
procedure TSettings.SetFrameColor(Value: TColor);
begin
if Value <> FFrameColor
then
begin
FFrameColor := Value;
//Invalidate;
end;
end;
{ ---------------------------------------------------------------------------- }
procedure TSettings.SetTextColor(Value: TColor);
begin
if Value <> FTextColor
then
begin
FTextColor := Value;
//Invalidate;
end;
end;
{ ---------------------------------------------------------------------------- }
end.