本文介绍了TabControl,遍历所有TextBoxes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个带有2个TabPages的TabControl.在每个TabPage上,我都有一些TextBoxes和ComboBoxes.在表单上还有一个下一步"按钮(onLoad Enabled = false),当所有TextBoxes/ComboBoxes都被填充时,应该激活该按钮.
要遍历TabPages上的所有TextBoxes/ComboBoxes,我将使用以下方法解决:

TabControl.TabPageCollection页面= tabControl.TabPages;
foreach(TabPage页面在页面中)
{
page.Refresh();
var firstEmptyTextBox =(从page.Controls.OfType< TextBox>()中的t开始) 其中String.IsNullOrEmpty(t.Text)
选择t).FirstOrDefault();

var firstEmptyComboBox =(从page.Controls.OfType< ComboBox>()中的t开始) 其中String.IsNullOrEmpty(t.Text)
选择t).FirstOrDefault();
btnNext.Enabled =
(firstEmptyTextBox ==空&& firstEmptyComboBox ==空);
}

但是在更改TextBox/ComboBox输入时应该检查TabControl/TabPage上的哪个事件?我尝试了"Enter,Click"等操作,但没有成功..
感谢您的帮助.控件.可以将就绪"/未就绪"状态放入自定义EventArgs对象.

当两个标签页均以适当的就绪/未就绪状态触发事件后,您就可以采取适当的措施.


hi guys,
I''ve got a TabControl with 2 TabPages. On each TabPage I''ve got some TextBoxes and ComboBoxes. On the Form there is as well a "Next" Button (onLoad Enabled=false) which should be activated when all TextBoxes/ComboBoxes are filled.
To loop through all the TextBoxes/ComboBoxes on the TabPages I''ll solve using:

TabControl.TabPageCollection pages = tabControl.TabPages;
foreach (TabPage page in pages)
{
page.Refresh();
var firstEmptyTextBox = (from t in page.Controls.OfType<TextBox>()
where String.IsNullOrEmpty(t.Text)
select t).FirstOrDefault();

var firstEmptyComboBox = (from t in page.Controls.OfType<ComboBox>()
where String.IsNullOrEmpty(t.Text)
select t).FirstOrDefault();
btnNext.Enabled =
(firstEmptyTextBox == null && firstEmptyComboBox == null);
}

but which Event on TabControl/TabPage should I check when changing the TextBox/ComboBox Input? I tried "Enter, Click" etc. without success..
Thanks for your help

解决方案


这篇关于TabControl,遍历所有TextBoxes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 00:27