繁体   English   中英

我如何加入两个控件集合以与foreach语句一起使用

[英]How do I join two control collections for use with foreach statement

根据问题,我在表单上有两个面板,一个叫做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;
                    }
                }
            }
        }
    }

这是我需要加入集合的行:

foreach(Control temp in leftPanel.Controls && rightPanel.Controls)

我意识到&&不起作用,也尝试过Controls.Concat,但是Control Collections似乎没有此功能。 希望一切都清楚了!

var allControls = leftPanel.Controls.Cast<Control>().Concat(rightPanel.Controls.Cast<Control>());
foreach(Control temp in allControls)
{
     //...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM