簡體   English   中英

選擇多個文本框以檢查是否為空

[英]Selecting more than 1 text box to check if it is empty

所以我做了一個小應用。 文本框有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;
}

我想知道如何檢查每個盒子中是否有單詞-即使“一個”盒子都是空的,我也不希望它執行。 如果這三個都填寫了,那么它可以繼續執行。

我會這樣做

if(this.Controls.OfType<TextBox>().All(t => string.IsNullOrEmpty(t.Text) == false))
{
  //carry out logic
}

“ this.Controls”是指文本框的父控件

似乎很簡單...

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM