检查文本框是否为空 [英] Check if TextBox is Empty or not

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

问题描述

我目前正在编程一个小的登录系统,并且试图阻止用户创建一个没有在TextBoxes中键入任何内容的帐户.这是我目前用于注册帐户的代码:

I'm currently programming a little login system and I'm trying to prevent users from creating an account with nothing typed into the TextBoxes. This is my current code for registering an account:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    TextBox1.Text = My.Settings.username
    TextBox2.Text = My.Settings.password

    If Trim(TextBox1.Text).Length < 1 AndAlso Trim(TextBox2.Text).Length < 1 Then
        MsgBox("Wrong username or password!")
    ElseIf Trim(TextBox1.Text).Length > 1 AndAlso Trim(TextBox2.Text).Length > 1 Then
        MsgBox("Your account was created!", MsgBoxStyle.Information, "Create")
        Me.Hide()
        Form1.Show()
    End If
End Sub

以某种方式,即使我输入了某些内容,它也总是会显示用户名或密码错误".如果输入内容为空,我如何使其仅响应用户名或密码错误"?

Somehow, it will always say "Wrong username or password" even if I type something in. How do I make it only respond "Wrong username or password" if the input is nothing?

我修复了代码.但是,如何使该人只能使用他注册的信息登录?

I fixed the code. But how do i make it possible that the person can only login with the information he registered?

推荐答案

可以尝试一下吗?就像上面Emilio所说的那样,请确保您的My.Settings.username和My.Settings.password没有传递任何值.

Can you try this? And as what Emilio mentioned above, please make sure that your My.Settings.username and My.Settings.password are not passing any values.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   TextBox1.Text = My.Settings.username
   TextBox2.Text = My.Settings.password

   If String.IsNullOrEmpty(TextBox1.Text) AndAlso String.IsNullOrEmpty(TextBox2.Text) Then
      MsgBox("Wrong username or password!")
   Else
      MsgBox("Your account was created!", MsgBoxStyle.Information, "Create")
      Me.Hide()
      Form1.Show()
   End If
End Sub

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

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