Einzelnen Beitrag anzeigen

Alex_ITA01

Registriert seit: 22. Sep 2003
1.115 Beiträge
 
Delphi 12 Athens
 
#2

Re: Komponenteneigenschaften ändern -> Invalidate ausführ

  Alt 5. Jan 2005, 14:29
Habs gelöst!!!
Lösung hier:

Delphi-Quellcode:
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;
    FOnEffectChange: TNotifyEvent;
    procedure SetHeaderCount(Value : Byte);
    procedure SetTextColor (Value : TColor);
    procedure SetFrameColor (Value : TColor);
    procedure DoChanges;
  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;
    property OnEffectChange: TNotifyEvent read FOnEffectChange write FOnEffectChange;
  end;

  THeaderListBox = class(TListBox)
  private
    { Private-Deklarationen }
    FSettings : TSettings;
    FHeaderControl : THeaderControl;
    procedure UpdateChanges(Sender: TObject);
  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('Jung', [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;

  FSettings := TSettings.Create;
  FSettings.OnEffectChange := UpdateChanges;

  if ComponentState = [csDesigning] then Exit;
end;
{ ---------------------------------------------------------------------------- }
procedure THeaderListBox.CreateWnd;
begin
  inherited CreateWnd;
  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;

  UpdateChanges(Self);
end;
{ ---------------------------------------------------------------------------- }
destructor THeaderListBox.Destroy;
begin
  if Assigned(FSettings) then
    FSettings.Free;
  inherited;
end;
{ ---------------------------------------------------------------------------- }
procedure THeaderListBox.UpdateChanges(Sender: TObject);
var
  i : Integer;
  HS: THeaderSection;
begin
  if Assigned(Settings) and Assigned(FHeaderControl) then
  begin
    FHeaderControl.Sections.Clear;
    for i := 0 to Settings.HeaderCount-1 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;
{ ---------------------------------------------------------------------------- }
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;
    DoChanges;
  end;
end;
{ ---------------------------------------------------------------------------- }
procedure TSettings.SetFrameColor(Value: TColor);
begin
  if Value <> FFrameColor then
  begin
    FFrameColor := Value;
    DoChanges;
  end;
end;
{ ---------------------------------------------------------------------------- }
procedure TSettings.SetTextColor(Value: TColor);
begin
  if Value <> FTextColor then
  begin
    FTextColor := Value;
    DoChanges;
  end;
end;
{ ---------------------------------------------------------------------------- }
procedure TSettings.DoChanges;
begin
  if Assigned(FOnEffectChange) then FOnEffectChange(Self);
end;
{ ---------------------------------------------------------------------------- }
end.
MFG Alex
Let's fetz sprach der Frosch und sprang in den Mixer
  Mit Zitat antworten Zitat