对窗体控件的循环

zbfeyan 2010-03-02 05:24:50
请问怎样对窗体的文本框、组合框进行循环,识别哪个文本框或组合框没有输入值?
怎么控制用于输入数字的文本框中的数字位数?
...全文
85 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hitlcyu19 2010-03-02
  • 打赏
  • 举报
回复
foreach (System.Windows.Forms.Control control in this.Controls)
{
if (control is System.Windows.Forms.TextBox)
{
System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)control ;
//有没有输入值 Text属性
//MaxLength
}
}
wuyq11 2010-03-02
  • 打赏
  • 举报
回复
For Each c As Windows.Forms.Control In Me.Controls
If TypeOf c Is Windows.Forms.ComboBox Then
Dim com As System.Windows.Forms.ComboBox = DirectCast(control, System.Windows.Forms.ComboBox )
ElseIf TypeOf c Is Windows.Forms.TextBox Then
Dim tb As System.Windows.Forms.TextBox = DirectCast(control, System.Windows.Forms.TextBox)
End If
Next
tjficcbw 2010-03-02
  • 打赏
  • 举报
回复
怎么控制用于输入数字的文本框中的数字位数?


Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If (TextBox1.Text).Length > 4 Then TextBox1.Text = (TextBox1.Text).Substring(0, 4)
End Sub



对窗体的文本框、组合框进行循环




For Each objCTRLS In Me.Controls
If TypeName(objCTRLS) = "textbox" or TypeName(objCTRLS) = "combobox" Then
'........
End If
Next objCTRLS


16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧