Today I was faced with the need to have some MDI child forms automatically size to fit their contents. These forms all descend from a base form that has an ExpressBars bar manager and an ExpressLayout layout control. I was surprised (though I shouldn’t be at this point) at how easy this was to achieve:
procedure TDataDetailsForm.FormShow(Sender: TObject); begin inherited; SizeToRootLayoutContents; end; procedure TDataDetailsForm.SizeToRootLayoutContents; begin ClientWidth := DetailsLayoutControlGroup_Root.ViewInfo.Bounds.Right - DetailsLayoutControlGroup_Root.ViewInfo.Bounds.Left + (DetailsLayoutControl.LayoutLookAndFeel.Offsets.RootItemsAreaOffsetHorz * 2); ClientHeight := DetailsLayoutControlGroup_Root.ViewInfo.Bounds.Bottom - DetailsLayoutControlGroup_Root.ViewInfo.Bounds.Top + (DetailsLayoutControl.LayoutLookAndFeel.Offsets.RootItemsAreaOffsetVert * 2) + DetailsBarManagerBar1.RealDockControl.Height; end;
With that bit of code in place, each form now automatically size to fit its contents when shown, but can still be freely resized.