2012-10-09 30 views
0

我有大約50個Maskedtextboxes,只有少數可見。我需要的是隻檢查可見的,如果他們是空的。如何檢查vb.net中的空可見Maskedtextboxes?

我用這個代碼來檢查所有Maskedtextboxes:

Dim empty = TabLABOR.Controls.OfType(Of MaskedTextBox)().Where(Function(txt) txt.Text.Length = 0) 
    If empty.Any Then 
     MessageBox.Show(String.Format("Please fill all fields", 
         String.Join(",", empty.Select(Function(txt) txt.Name)))) 
    Else 
     TabControlBlockD.SelectTab(TabMATERIALS) 
    End If 

End Sub 

回答

0

你應該使用每個像下面

dim myfrm as MyCurrentForm() 

然後

for Each item As System.Windows.Forms.Control In myfrm.Controls 
     If item.GetType Is GetType(System.Windows.Forms.MaskedTexbox) Then 
      For Each mboxes As MaskedTexbox In item.Controls 
       If MaskedTexbox.text = "" AND maskedTextbox.visible = true Then 
        //Make deltu king of the world 
       End If 
      Next 
     End If 
    Next 

這應該工作。

編輯:

+0

謝謝,感謝你。但這並不是我想要的,我想要的只是檢查可見的。 –

+0

哦。放在if語句中,條件是它應該是可見的。我相信這是用maskedtextbox.visible = true完成的 – deltu100