Reputation: 1151
As per the question I have two panels on my form one called leftPanel and one called rightPanel. These control a two column layout on my form.
I also have collapsing/expanding groupboxes inside these panels and I wish to iterate over each one to refresh the layout causing them to snap up below each other when the sizing changes.
Here is the code I have:
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;
}
}
}
}
}
This is the line where I need to join the collections:
foreach(Control temp in leftPanel.Controls && rightPanel.Controls)
I realise that && does not work, have also tried Controls.Concat but Control Collections do not seem to have this function. Hope everything is clear!
Upvotes: 0
Views: 1134
Reputation: 1332
var allControls = leftPanel.Controls.Cast<Control>().Concat(rightPanel.Controls.Cast<Control>());
foreach(Control temp in allControls)
{
//...
}
Upvotes: 12