在TabControl中循环控制 [英] Loop through controls in TabControl
问题描述
我正在寻找一种方式来循环控制tabcontrol的特定选项卡上的控件。例如,我有一个tabcontrol与下列标签:
汽车,
宠物,
管理
每个选项卡上有几个控件来显示/编辑/保存数据等。在保存按钮上,我想遍历该特定选项卡的控件,检查是否所有必填字段所以,如果我在汽车选项卡上,然后单击保存,我只想循环通过汽车选项卡上的控件,而不是宠物或管理员标签。
如何才能达到这个结果?
为了遍历TabControl的控件,你需要使用Controls属性。
这是一个有关TabControl的MSDN文章。
示例:
TabPage page = aTabControl.SelectedTab;
var controls = page.Controls;
foreach(控件中的var控件)
{
//做东西
}
I am looking for a way to loop through controls on a particular tab of a tabcontrol. For example, I have a tabcontrol with the following tabs:
Cars, Pets, Admin
On each of these tabs are several controls to display/edit/save data, etc. On the "Save" button, I would like to loop through the controls for that particular tab to check whether all required fields have been filled in.
So, if I am on the Cars tab and click "Save," I want to loop ONLY through the controls on the Cars tab and NOT the Pets or Admin tabs.
How can achieve this result?
As for looping through a TabControl's controls, you need to use the Controls property.
Here's an MSDN article on the TabControl.
Example:
TabPage page = aTabControl.SelectedTab;
var controls = page.Controls;
foreach (var control in controls)
{
//do stuff
}
这篇关于在TabControl中循环控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!