我已经对文本框进行了验证以检查它们是否为空,但即使禁用了文本框,也会检查条件并根据验证消息进行显示
文本框不能为空
if ((txt1Yes1.Text.Equals(string.Empty) || txt1Yes2.Text.Equals(string.Empty))
MessageBox.Show("Please Enter All The Details");
我已经写过这个,只有在启用了文本框的情况下才能进行检查。
答案 0 :(得分:0)
无论是否禁用if
控件,您都可以添加额外的TextBox
条件。
void validateDetails()
{
if (txt1Yes1.Enabled && txt1Yes2.Enabled)
{
if ((txt1Yes1.Text.Equals(string.Empty) || txt1Yes2.Text.Equals(string.Empty)))
{
MessageBox.Show("Please Enter All The Details");
}
}
}
要检查TextBox
控件是否已禁用(切换),我已使用CheckedChanged(...)
控件的checkBox
事件。
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
foreach (Control control in this.Controls)
{
if (control is TextBox)
{
TextBox tbox = control as TextBox;
if (checkBox1.Checked)
{
tbox.Enabled = false;
}
else
tbox.Enabled = true;
}
}
}
答案 1 :(得分:0)