Hallo oki,
bei meinem Q&D-Testprogramm habe ich keine Probleme feststellen können:
Delphi-Quellcode:
type
TMyControl = class (TCustomControl)
private
FHeaderVisible: Boolean;
procedure SetHeaderVisible(aValue: Boolean);
protected
procedure AdjustClientRect(var Rect: TRect); override;
procedure Paint; override;
public
property HeaderVisible: Boolean read FHeaderVisible write SetHeaderVisible;
end;
TForm1 = class (TForm)
btnToggleHeader: TButton;
procedure btnToggleHeaderClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
FMyControl: TMyControl;
end;
{ TMyControl }
const
HEADERSIZE = 16;
procedure TMyControl.AdjustClientRect(var Rect: TRect);
begin
inherited;
Inc (Rect.Top, HEADERSIZE * Ord(FHeaderVisible));
end;
procedure TMyControl.Paint;
begin
Canvas.Brush.Color := clYellow;
Canvas.TextRect (Rect(0, 0, ClientWidth, HEADERSIZE), 4, 2, 'Hello world!');
end;
procedure TMyControl.SetHeaderVisible(aValue: Boolean);
begin
FHeaderVisible := aValue;
Realign; // fehlt das bei dir?
end;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
FMyControl := TMyControl.Create(Self);
FMyControl.Parent := Self;
FMyControl.SetBounds (16, 16, 240, 160);
with TLabel.Create(Self) do
begin
Parent := FMyControl;
Align := alClient;
Alignment := taCenter;
Layout := tlCenter;
Color := clRed;
Caption := 'Label';
end;
end;
procedure TForm1.btnToggleHeaderClick(Sender: TObject);
begin
FMyControl.HeaderVisible := not FMyControl.HeaderVisible;
end;
Vielleicht fehlt in deiner Implementierung ein Aufruf der Methode
Realign?
Gruß Hawkeye