Hi @Hans ,
The Dock property takes effect based on the z-order of controls in the Controls collection. When you add a new panel with DockStyle.Fill after the splitters and other panels, it might cause other docked elements (e.g., DockStyle.Left splitters) to be pushed or misaligned.
Splitters need to be correctly placed between panels with DockStyle.Left. If the last panel is DockStyle.Fill, it can disrupt the layout because DockStyle.Fill expands to occupy any remaining space, pushing other controls unexpectedly.
Try using DockStyle.Left for intermediate panels and splitters, and DockStyle.Fill for the final panel.
private void CreateBodyPanelsAndSplitters(Panel panelLeft, Panel panelRight)
{
for (int i = 1; i <= _numberOfPanels; i++)
{
if (i == 1) // Left split container panel
{
Panel p = CreatePanel(i, DockStyle.Fill, _panelBodyName, Color.AliceBlue);
panelLeft.Controls.Add(p);
}
else // Right split container panel
{
if (i < _numberOfPanels)
{
// Intermediate panels and splitters
Panel p = CreatePanel(i, DockStyle.Left, _panelBodyName, Color.AliceBlue);
Splitter s = CreateSplitter(i);
// Add the splitter before the panel to ensure correct layout
panelRight.Controls.Add(p);
panelRight.Controls.Add(s);
}
else
{
// Last panel with DockStyle.Fill
Panel p = CreatePanel(i, DockStyle.Fill, _panelBodyName, Color.AliceBlue);
panelRight.Controls.Add(p);
}
}
}
}
Best Regards.
Jiachen Li
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.