Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何连接两个控件集合以与foreach语句一起使用_C#_Collections_Controlcollection - Fatal编程技术网

C# 如何连接两个控件集合以与foreach语句一起使用

C# 如何连接两个控件集合以与foreach语句一起使用,c#,collections,controlcollection,C#,Collections,Controlcollection,根据这个问题,我的表格上有两个面板,一个叫做leftPanel,另一个叫做rightPanel。这些控件控制窗体上的两列布局 我在这些面板中也有折叠/扩展的GroupBox,我希望在每个面板上进行迭代以刷新布局,从而在大小改变时使它们在彼此下方对齐 以下是我的代码: private void RefreshLayout() { int rollingTopLeft = grpiAddressDetails.Top + grpiAddressDetails.Heig

根据这个问题,我的表格上有两个面板,一个叫做leftPanel,另一个叫做rightPanel。这些控件控制窗体上的两列布局

我在这些面板中也有折叠/扩展的GroupBox,我希望在每个面板上进行迭代以刷新布局,从而在大小改变时使它们在彼此下方对齐

以下是我的代码:

    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)
我意识到&&不起作用,也尝试过控件。Concat但控件集合似乎没有此功能。 希望一切都清楚

var allControls=leftPanel.Controls.Cast().Concat(rightPanel.Controls.Cast());
var allControls = leftPanel.Controls.Cast<Control>().Concat(rightPanel.Controls.Cast<Control>());
foreach(Control temp in allControls)
{
     //...
}
foreach(所有控制中的控制温度) { //... }
使用
.Cast
需要什么?