in the middle of the application is a frame. After resizing i need to rearrange controls on this panel (doing this in the resizing event is too busy). Its more useful if this can be done once after all the resizing. But how?
Thank you for your help
You could try the following Implementation.
-Hook owner form's on Resize event, handle it within your frame, and Fire any Event Handler the parent OnResize Might have had.
type
TFrame2 = class(TFrame)
Label1: TLabel;
procedure FrameClick(Sender: TObject);
private
{ Private declarations }
FOnResize: TNotifyEvent;
procedure OnFrameResize(Sender: TObject);
public
{ Public declarations }
// custom Frame constructor
constructor Create(AOwner: TComponent); override;
end;
implementation
{$R *.dfm}
{ TFrame2 }
constructor TFrame2.Create(AOwner: TComponent);
begin
inherited;
FOnResize := TForm(AOwner).OnResize;
TForm(AOwner).OnResize := OnFrameResize;
end;
procedure TFrame2.OnFrameResize(Sender: TObject);
begin
Label1.Caption := 'resize fired';
if @FOnResize <> nil then
FOnResize(Parent);
end;
1) Mark your frame with special interface smth. like: INeedLayoutAfterResize :)
2) Write custom descendant of TForm that would capture resize events (as shown in earlier answers), than looks for its children and if some child marked, than re-layout its content.
actually I use such approach for save and restore controls state. my custom from iterate over its children controls and look for Tag property if it is less then zero, write its state to ini-file.
The trick is to hook into message processing of the parent form (proof-of-concept code, tested with Delphi 2009, error and corner case handling need more work):
Note that the messages are sent whenever a secondary message loop for moving / sizing has been started or left - there is no way to distinguish between moving and sizing. If you need to make sure that you catch sizing only, you should compare old and new size of the frame in the handler.