How do you make a TFrame's OnResize event occur when it first appears?

766 views Asked by At

I have a frame that is being placed on a form. I expect to be placing a number of instances of this frame on the form.

It has a drawgrid with 2 columns and in the OnResize event I make the 2nd column extend to the end of the available space. That works when the form is manually resized with the frame Align set to alTop. But when the form first appears even though FrameResize gets called it has no effect. (Though it did have the desired effect when I put a break point on it).

So, what I am doing now is calling the FrameResize from the forms OnShow handler, but that is ugly. The frame should be able to appear correctly formed without help from the Form.

Any ideas? I did try overriding SetParent, but that didn't work. Using Xe2.

TIA Mark

1

There are 1 answers

0
Mark Patterson On

I have solved it with advice from Peter Below, Delphi Team B Delphi member.

I overrode the frame's set bounds. It was getting called even before the component variables were set, so it looks like this

procedure TfaDupDisplay.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);  // Had to use SetBounds because OnRezise was not working
var grid: TDrawGrid;
begin
  inherited;
  if pnlWebData = nil then
    exit;
  pnlWebData.Width := Width div 2;
  for grid in TArray<TDrawGrid>.Create(grdData, grdDup) do
    grid.ColWidths[1] := grid.Width - grdData.ColWidths[0];
end{ SetBounds};