C#忽略空文本框 [英] C# ignore empty textboxes

查看:79
本文介绍了C#忽略空文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我一直在寻找一种方法来检查表单中的所有文本框是否为空,如果没有显示消息。其中一些是不可见的。

我有下面的代码,但它不能以某种方式工作,当我点击确定我得到一个错误,因为文本框是空的。



有人可以帮忙吗?



提前付款



我尝试过:



Hi,

i´ve been searching for a way to check if all textboxes from a form a empty and if not show a message. Some of them are not visible.
I have the code below but it´s not working somehow, when i click ok i get an error because a textbox is empty.

Can anyone help please ?

Thanks in advance

What I have tried:

foreach (Control c in Controls)
{
    if (c is TextBox && c.Visible && string.IsNullOrEmpty(c.Text))
    {
        MessageBox.Show($"TextBox {c.Name} is empty");
    }
}

推荐答案

< span class =code-string> TextBox {c.Name}为空);
}
}
"TextBox {c.Name} is empty"); } }


希望我理解正确,但为什么不使用控件可见状态来确定是否测试盒子;



Hope I understand correctly but why not use the controls visible state to determine whether to test the box or not;

if (larg.Text == string.Empty)
{
    if (larg.Visible == False)
    {
      MessageBox.Show(&quot;info missing&quot;, &quot;Warning&quot;);
      return;
    }
}





Etcetera。



Etcetera.


这篇关于C#忽略空文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆