根据问题,我在表单上有两个面板,一个叫做leftPanel,另一个叫做rightPanel.它们控制我表单上的两列布局.
我还在这些面板中折叠/扩展了组框,我希望迭代每个组以刷新布局,使它们在大小调整更改时互相抢购.
这是我的代码:
private void RefreshLayout()
{
int rollingTopLeft = grpiAddressDetails.Top + grpiAddressDetails.Height + 10;
int rollingTopRight = grpiBranding.Top + grpiBranding.Height + 10;
foreach(Control temp in leftPanel.Controls && rightPanel.Controls)
{
if (temp is GroupBox)
{
if (!(temp.Name.Contains("grpi"))) // Top group boxes have 'i' as the 4th character in their name.
{
if (temp.Parent == leftPanel)
{
temp.Top = rollingTopLeft;
rollingTopLeft += temp.Height + 10;
}
else if(temp.Parent == rightPanel)
{
temp.Top = rollingTopRight;
rollingTopRight += temp.Height + 10;
}
} …Run Code Online (Sandbox Code Playgroud)