Skip to main content

How to Arrange Toolbars

When a user moves toolbars at runtime, separations between individual toolbars may be created based on the placement of these toolbars. The following code demonstrates how you can arrange toolbars docked to a form’s top, to eliminate this free space.

// ...
procedure TMainForm.ArrangeBarsButtonClick(Sender: TObject);
var
  I, J, Offset: Integer;
  DockRow: TdxDockRow;
begin
  with dxBarManager do
  begin
    BeginUpdate;
    try
      for J := 0 to Bars.DockControls[dsTop].RowList.Count - 1 do
      begin
        DockRow := TdxDockRow(Bars.DockControls[dsTop].RowList[J]);
        Offset := 0;
        for I := 0 to DockRow.ColList.Count - 1 do
          with TdxDockCol(DockRow.ColList[I]) do
          begin
            Pos := Point(Offset, Pos.Y);
            Inc(Offset, BarControl.Width);
          end;
      end;
    finally
      EndUpdate;
    end;
  end;
end;