读书人

怎么通过循环语句确定窗体下文本框是否

发布时间: 2012-08-07 14:54:48 作者: rapoo

如何通过循环语句确定窗体上文本框是否为空记录
如何通过循环语句确定窗体上文本框是否为空记录

[解决办法]

VB.NET code
     For Each c As Control In Me.Controls            If c.GetType() Is GetType(TextBox) Then                If c.Text.Length = 0 Then  'If c.Text.Trim().Length = 0 Then                     MessageBox.Show(String.Format("文本框{0}值为空", c.Name))                End If            End If        Next
[解决办法]
private sub SetText(Ct as control)
For Each c As Control In Me.Controls
If c.GetType() Is GetType(TextBox) Then
If c.Text.Length = 0 Then 'If c.Text.Trim().Length = 0 Then
Console.WriteLine(String.Format("文本框{0}值为空", c.Name))
If c.HasChildren Then
SetText(c)
End If
End If
End If
Next
End sub
[解决办法]
探讨

如果包括文本框、组合框一起检查怎么办?如果有个别文本框允许这空,只检查其他不允许为空的文本框怎么办?

读书人网 >VB Dotnet

热点推荐