Einzelnen Beitrag anzeigen

Benutzerbild von Uwe Raabe
Uwe Raabe

Registriert seit: 20. Jan 2006
Ort: Lübbecke
11.035 Beiträge
 
Delphi 12 Athens
 
#6

AW: Dynamische Multipanel Anordnung - Seitenverhältnis bei Resize

  Alt 23. Jan 2023, 12:23
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.
Uwe Raabe
Certified Delphi Master Developer
Embarcadero MVP
Blog: The Art of Delphi Programming

Geändert von Uwe Raabe (23. Jan 2023 um 12:26 Uhr)
  Mit Zitat antworten Zitat