[英]Selecting more than 1 text box to check if it is empty
So I made a small application. 所以我做了一个小应用。 There is 6 sections of text boxes, 3 in each section.
文本框有6个部分,每个部分3个。
string location;
Random lc = new Random();
byte i5 = (byte)lc.Next(3);
switch (i5)
{
case 0:
location = l1.Text;
break;
case 1:
location = l2.Text;
break;
case 2:
location = l3.Text;
break;
}
I am wondering how to make a check to see if each box has a word in it - if even 'one' box is empty, then I don't want it to execute. 我想知道如何检查每个盒子中是否有单词-即使“一个”盒子都是空的,我也不希望它执行。 If all three are filled in, then it can continue executing.
如果这三个都填写了,那么它可以继续执行。
I would do this 我会这样做
if(this.Controls.OfType<TextBox>().All(t => string.IsNullOrEmpty(t.Text) == false))
{
//carry out logic
}
"this.Controls" refers to the parent control of the textboxes “ this.Controls”是指文本框的父控件
Seems simple enough... 似乎很简单...
if String.IsNullOrEmpty(l1.Text) return;
if String.IsNullOrEmpty(l2.Text) return;
if String.IsNullOrEmpty(l3.Text) return;
if ....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.