Skip to main content

How to Create a Toolbar and Position it on Screen

  • 2 minutes to read

The following function creates a new toolbar and sets it to a desired position on screen. The parameters used are as follows:

ABarManager Specifies the bar manager which manages the toolbar.
ACaption Specifies the caption of the new toolbar.
ADockingStyle Specifies the dock control onto which the toolbar is placed.
ARow and ACol Specifies toolbar position on a dock control. It is used if ADockingStyle does not equal dsNone.
AInsert If True, a new toolbar will occupy the entire row in a dock control.
AIsVisible Determines, whether a new toolbar will be visible.
function CreateBar(ABarManager: TdxBarManager; ACaption: string; ADockingStyle: TdxBarDockingStyle; ARow, ACol: Integer; AInsert: Boolean; AVisible: Boolean): TdxBar;
var
  AIsVertical: Boolean;
  ADockRow: TdxDockRow;
begin
  Result := ABarManager.Bars.Add;
  with Result do
  begin
    Caption := ACaption;
    DockingStyle := ADockingStyle;
    if ARow < 0 then ARow := 0;
    Row := ARow;
    OneOnRow := AInsert;
    if (ACol <> -1) and (DockingStyle <> dsNone) then
    begin
      DockControl := TdxBarDockControl(BarManager.Bars.DockControls[DockingStyle]);
      if Row < DockControl.RowList.Count then
      begin
        AIsVertical := DockingStyle in [dsLeft, dsRight];
        ADockRow := TdxDockRow(DockControl.RowList[Row]);
        if ADockRow.ColList.Count > 0 then
        begin
          if ACol < 0 then ACol := 0;
          if ACol >= ADockRow.ColList.Count then
            with TdxDockCol(ADockRow.ColList.Last) do
            if AIsVertical then
              Result.DockedTop := DockedTop + BarControl.Height
            else
              Result.DockedLeft := DockedLeft + BarControl.Width
          else
            with TdxDockCol(ADockRow.ColList[ACol]).Pos do
              if AIsVertical then DockedTop := Y
              else DockedLeft := X;
          end;
        end;
    end;
    Visible := AVisible;
  end;
end;