Versuch es doch mal mit dem Aufruf von ResizePlayerGrid im FormCreate, dem Resize-Event des Grids und bei Änderung des Seitenverhältnisses (hier beispielhaft für 4:3 und 16:9):
Delphi-Quellcode:
procedure ResizeControlWithAspectRatio(AControl: TControl; RatioWidth, RatioHeight: Integer);
var
actWidth: Integer;
actHeight: Integer;
calcHeight: Integer;
calcWidth: Integer;
margin: Integer;
margin1: Integer;
margin2: Integer;
begin
actWidth := AControl.Margins.ControlWidth;
actHeight := AControl.Margins.ControlHeight;
calcHeight := MulDiv(actWidth, RatioHeight, RatioWidth);
calcWidth := MulDiv(actHeight, RatioWidth, RatioHeight);
if calcHeight < actHeight then
begin
margin := actHeight - calcHeight;
margin1 := margin div 2;
margin2 := margin - margin1;
AControl.Margins.SetBounds(0, margin1, 0, margin2);
end
else
begin
margin := actWidth - calcWidth;
margin1 := margin div 2;
margin2 := margin - margin1;
AControl.Margins.SetBounds(margin1, 0, margin2, 0);
end;
end;
procedure ResizePlayerGrid(AGrid: TGridPanel; AWideScreen: Boolean);
var
ratioHeight: Integer;
ratioWidth: Integer;
begin
ratioWidth := 4*AGrid.ColumnCollection.Count;
ratioHeight := 3*AGrid.RowCollection.Count;
if AWideScreen then begin
ratioWidth := 4*ratioWidth;
ratioHeight := 3*ratioHeight;
end;
ResizeControlWithAspectRatio(AGrid, ratioWidth, ratioHeight);
end;
Update: Ach ja: AlignWithMargins muss bei dem Grid aktiv sein.