Reputation: 21221
I want to create a custom TPanel that has a TImage32 in it.
The image won't align to the parent until I manually resize the parent control. After that it will stay nicely aligned.
Why?
TYPE
TDisplay1= class(TPanel)
private
Ready: Boolean;
RightPnl : TPanel;
ShowA : TSpeedButton;
Display : TImage32;
protected
procedure Resize; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
IMPLEMENTATION
procedure TDisplay1.Resize; <-------- the culprit was here as suggested by Vahid
begin
inherited;
if Ready
then Display.SetupBitmap(TRUE, clYellow32);
end;
Update:
I am working o a solution with an alternative way to load the control. I will let you know if I succeed.
Update2:
Vahid answer's was better. Thanks Vahid.
Upvotes: 0
Views: 520
Reputation: 584
Add this code to your panel:
...
protected
procedure Paint; override;
...
procedure TDisplay1.Paint;
begin
inherited;
if Ready then Display.SetupBitmap(TRUE, clYellow32);
end;
Upvotes: 3