Question

I am trying to reset a group of toolbar locations inside a TControlBar. The user has the ability to drag the toolbars around and undock them. I am trying to create reset button that will rearrange the toolbars is a preset fashion.

I am having trouble getting the toolbars to reset in the order that I want them. The results of my ManualDock calls seem to vary depending on how things were arranged before my code executes.

I have 4 toolbars that I want arranged in two rows like this:

[Toolbar1][Toolbar2]
[Toolbar3][Toolbar4]

I have tried variants of the following code without success:

// I found some references to different docking issues when controls were visible
// Hide everything first and then show them in the order I want them added.
Toolbar1.Visible := false;
Toolbar2.Visible := false;
Toolbar3.Visible := false;
Toolbar4.Visible := false;

ToolBar1.Visible := true;
ToolBar1.ManualDock(DockSite);
ToolBar1.Left := 0;

Toolbar2.Visible := true;
Toolbar2.ManualDock(DockSite, Toolbar1, alRight);

Toolbar3.Visible := true;
Toolbar3.ManualDock(DockSite, Toolbar1, alBottom);
Toolbar3.Left := 0;

Toolbar4.Visible := true;
Toolbar4.ManualDock(DockSite, Toolbar3, alRight);

The results on screen are different depending on where the toolbars started before my code executes.

I have tried several different approaches - Setting the toolbars top and left after the manual dock call - alLeft/alTop instead of the options above - Using Nil as the second parm in the ManualDock call and setting everything to alTop

I tried working with just 2 toolbars to force them to appear either on the same row (side by side) or in two rows. Again my results were different depending on where the toolbars started out before my code executed.

Was it helpful?

Solution

Hiding, docking, setting positions and showing should lead to the expected result.

begin
  ToolBar1.Visible := false;
  ToolBar2.Visible := false;
  ToolBar3.Visible := false;
  ToolBar4.Visible := false;
  ToolBar1.ManualDock(ControlBar1);
  ToolBar2.ManualDock(ControlBar1);
  ToolBar3.ManualDock(ControlBar1);
  ToolBar4.ManualDock(ControlBar1);

  ToolBar1.Left := 0;
  ToolBar1.Top := 0;
  ToolBar2.Left := ToolBar1.Width;
  ToolBar2.Top := 0;
  ToolBar3.Left := 0;
  ToolBar3.Top := MAX(ToolBar1.Height, ToolBar2.Height);
  ToolBar4.Left := ToolBar3.Width;
  ToolBar4.Top := ToolBar3.Top;

  ToolBar1.Visible := true;
  ToolBar2.Visible := true;
  ToolBar3.Visible := true;
  ToolBar4.Visible := true;
end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top