在我的表单中,几乎有 30-35 个控件,有些是启用的,有些是禁用的,例如如果该人未婚并且如果用户选择他们已婚,则禁用配偶姓名,则启用该控件。
最初,提交按钮被禁用,但一旦所有启用的字段都填满,我希望提交按钮自动启用。
为此,我已经完成了这段代码。
if ((nametxt.Text != null) && (f_nametxt.Text != null) &&
(m_nametxt.Text != null) && (gotra_txt.Text != null) &&
(panthcb.Text != null) && (fhntext.Text != null) &&
(edulvlcb.Text != null) && (bloodcb.Text != null) &&
(MarritalStatus != null) && (s_nametxt.Text != null) &&
(s_edulvlcb.Text != null) && (s_bgcb.Text != null) &&
(ressi_addresstxt.Text != null) && (ressi_phnotxt.Text != null) &&
(mobi_notxt.Text != null) && (office_addresstxt.Text != null) &&
(occup_typetxt.Text != null) && (occup_naturecb.Text != null) &&
(office_phno1txt.Text != null) && (office_mobnotxt.Text != null))
{
submit_addbtn.Enabled = true;
}
我不知道这是否正确以及我应该在哪里(以何种形式)这样做。
请告诉我并帮助我。
这是文本框的代码完成keydown事件,此事件未触发
private void mobi_notxt_KeyDown(object sender, KeyEventArgs e)
{
foreach (Control c in this.Controls)
{
TextBox txt = c as TextBox;
if (txt != null)
{
if (!(txt.Enabled && txt.Text != ""))
{
allFilled = false;
break;
}
}
}
if (allFilled)
{
submit_addbtn.Enabled = true;
}
else
{
submit_addbtn.Enabled = false;
}
}