检查表单VB.net中的文本框的空值 [英] check empty value of Textboxs in Form VB.net

查看:201
本文介绍了检查表单VB.net中的文本框的空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如我有3个TextBox,如果其中一个有空值那么

i需要它提醒这样的消息>>请输入值到txtName<<<< / xml>

解决方案

Google用于VB.NET Windows窗体验证,您将提出各种方法来实现此目的。


只需这样做,如果你想以同样的方式使用循环..



  If  YourTextBox.Text =    字符串 .IsNullOrEmpty(YourTextBox.Text)然后 
MessageBox.Show( 请在YourTextBox中输入值
txtFileName.Focus()
退出 Sub
结束 如果


您好,



使用此代码检查表格的空白文本框



< pre lang =vb> 私有 Sub Button1_Click(发件人正如 对象,e As EventArgs)句柄 Button1.Click
尝试
对于 每个 cntrl 作为控制 .Controls()
如果 TypeOf cntrl TextBox 然后
如果 CType (cntrl,TextBox).Text.Equals(字符串 .Empty) CType (cntrl,TextBox).Text = 然后
MessageBox.Show ( 请在& ;; cntrl.Name.ToString())
结束 如果
结束 如果
下一步
< span class =code-keyword> Catch ex As 例外

结束 尝试

结束


For Example I have 3 TextBoxs if one of them have empty value then
i need it alert a message like that >>Please Enter Values into txtName <<<</xml>

解决方案

Google for "VB.NET Windows Forms Validation" and you'll come up with all kinds of ways to do this.


simply do this,use loop if you want the same way you did..

If YourTextBox.Text = "" Or String.IsNullOrEmpty(YourTextBox.Text) Then
            MessageBox.Show("Please Enter Values into YourTextBox")
            txtFileName.Focus()
            Exit Sub
End If


Hi,

Use this code to check the blank textbox for a form

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            For Each cntrl As Control In Me.Controls()
                If TypeOf cntrl Is TextBox Then
                    If CType(cntrl, TextBox).Text.Equals(String.Empty) Or (CType(cntrl, TextBox).Text = "") Then
                        MessageBox.Show("Please enter value in " & cntrl.Name.ToString())
                    End If
                End If
            Next
        Catch ex As Exception

        End Try

    End Sub


这篇关于检查表单VB.net中的文本框的空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆