Reputation: 12584
I have the following structure of panels
and from the code I need to align the bottom panel depending of situation on right,bottom or left. Align the splitter to right and bottom does not pose problems, but align the splitter to left I can't do
the code responsible for the alignment of the panels and splitters
procedure TForm1.alignThem;
begin
case CommentPanelPosition of
0: begin
pROComponents.Align := alRight;
sROSplitterComponents.Align := alRight;
sROSplitterComponents.width := 3;
pROComponents.Width := GridPanel.Width div 4;
end;
1:
begin
pROComponents.height := GridPanel.height div 3;
end;
2:
begin
pROComponents.Align := alLeft;
TabellePanel.Align := alClient;
sROSplitterComponents.Align := alLeft
end;
end;
end;
where
CommentPanelPosition
is
0 when splitter is located on right
1 when splitter is located on bottom
2 when splitter is located on the left
How can I manage the problem when aligning the splitter to left?
Upvotes: 2
Views: 4300
Reputation: 116200
After aligning the splitter, set pROComponents.Left := 0;
,
begin
pROComponents.Align := alLeft;
TabellePanel.Align := alClient;
sROSplitterComponents.Align := alLeft;
pROComponents.Left := 0;
end;
You have two components that are aligned left (splitter and panel). The last one that is moved to the left is the splitter. It's left position is already 0 at that point, causing it to move to the far left and pushing the panel to the right.
So a different solution could be to first align the splitter left and then align the panel to the left.
But..
I believe that the Left-property at the moment of realigning is important, so if the panel was aligned right and the splitter as well, and you move them left (splitter first, then the panel), the panel will probably be right of the splitter again, because its Left
property was greater than 0 at the time of realigning.
Therefor, I feel safer by setting the appropriate property of the control(s) being split, so they are in the right position.
The splitter seems a smart component, but there is no way to directly associate it with two controls. When designing the form, or realigning it in code, the splitter has no idea which controls it belongs to and it will not attempt to position itself in a logical position inbetween your panels. It just follows the normal rules that apply to each control and only finds the right control when you actually start moving the splitter using your mouse.
So, setting the Left (or Right, Top, Bottom) property of the panel is actually just a work-around for this lacking functionality of the splitter.
Upvotes: 5