gna*_*ket 6 c# foreach winforms
我有一个winforms TabControl,我试图循环遍历每个选项卡中包含的所有控件.有没有办法and在foreach循环中添加或者不可能评估多个项目组?例如,这就是我想要做的:
foreach (Control c in tb_Invoices.Controls and tb_Statements.Controls)
{
//do something
}
Run Code Online (Sandbox Code Playgroud)
要么
foreach (Control c in tb_Invoices.Controls, tb_Statements.Controls)
{
//do something
}
Run Code Online (Sandbox Code Playgroud)
这是可能的,如果没有,那么下一个最好的东西是什么?我需要使用for循环吗?
foreach(TabPage page in yourTabControl.TabPages){
foreach(Control c in page.Controls){
LoopThroughControls(c);
}
}
private void LoopThroughControls(Control parent){
foreach(Control c in parent.Controls)
LoopThroughControls(c);
}
Run Code Online (Sandbox Code Playgroud)