更改文本框中的内容后,第一次单击时不显示MsgBox

时间:2014-04-22 08:43:00

标签: vb.net visual-studio

我试图通过创建这个基本形式来学习。在哪里向用户询问密码和用户名 目前都是文本字段和不安全。 问题是每当我更改2个字段中的任何一个时,第一次点击都不起作用。 从第二次点击开始,代码工作正常。

编辑 - 在用户和密码错误之前没有问题。

这是片段

Private Sub BtnLogIn_Click(sender As Object, e As EventArgs) Handles BtnLogIn.Click
    If (TxtUsername.Text = "shikhar" And TxtPassword.Text = "pass") Then
        'goto next screen & remove message box'
        MsgBox("correct Username or Password", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "login Completed")
    Else
        MsgBox("Incorrect Username or Password", MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "login error")

    End If
End Sub

enter image description here

这是整个文件 -

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Login
Inherits System.Windows.Forms.Form

'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
    Try
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
    Finally
        MyBase.Dispose(disposing)
    End Try
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.  
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
    Me.lblUsername = New System.Windows.Forms.Label()
    Me.lblPassword = New System.Windows.Forms.Label()
    Me.TxtUsername = New System.Windows.Forms.TextBox()
    Me.TxtPassword = New System.Windows.Forms.TextBox()
    Me.BtnLogIn = New System.Windows.Forms.Button()
    Me.SuspendLayout()
    '
    'lblUsername
    '
    Me.lblUsername.AutoSize = True
    Me.lblUsername.Location = New System.Drawing.Point(69, 84)
    Me.lblUsername.Name = "lblUsername"
    Me.lblUsername.Size = New System.Drawing.Size(55, 13)
    Me.lblUsername.TabIndex = 0
    Me.lblUsername.Text = "Username"
    '
    'lblPassword
    '
    Me.lblPassword.AutoSize = True
    Me.lblPassword.Location = New System.Drawing.Point(69, 130)
    Me.lblPassword.Name = "lblPassword"
    Me.lblPassword.Size = New System.Drawing.Size(53, 13)
    Me.lblPassword.TabIndex = 1
    Me.lblPassword.Text = "Password"
    '
    'TxtUsername
    '
    Me.TxtUsername.Location = New System.Drawing.Point(178, 77)
    Me.TxtUsername.Name = "TxtUsername"
    Me.TxtUsername.Size = New System.Drawing.Size(199, 20)
    Me.TxtUsername.TabIndex = 2
    '
    'TxtPassword
    '
    Me.TxtPassword.Location = New System.Drawing.Point(178, 123)
    Me.TxtPassword.Name = "TxtPassword"
    Me.TxtPassword.Size = New System.Drawing.Size(198, 20)
    Me.TxtPassword.TabIndex = 3
    '
    'BtnLogIn
    '
    Me.BtnLogIn.Location = New System.Drawing.Point(181, 172)
    Me.BtnLogIn.Name = "BtnLogIn"
    Me.BtnLogIn.Size = New System.Drawing.Size(164, 45)
    Me.BtnLogIn.TabIndex = 4
    Me.BtnLogIn.Text = "Log In"
    Me.BtnLogIn.UseVisualStyleBackColor = True
    '
    'Login
    '
    Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
    Me.ClientSize = New System.Drawing.Size(474, 261)
    Me.Controls.Add(Me.BtnLogIn)
    Me.Controls.Add(Me.TxtPassword)
    Me.Controls.Add(Me.TxtUsername)
    Me.Controls.Add(Me.lblPassword)
    Me.Controls.Add(Me.lblUsername)
    Me.Name = "Login"
    Me.Text = "Login"
    Me.ResumeLayout(False)
    Me.PerformLayout()

End Sub
Friend WithEvents lblUsername As System.Windows.Forms.Label
Friend WithEvents lblPassword As System.Windows.Forms.Label
Friend WithEvents TxtUsername As System.Windows.Forms.TextBox
Friend WithEvents TxtPassword As System.Windows.Forms.TextBox
Friend WithEvents BtnLogIn As System.Windows.Forms.Button
End Class

0 个答案:

没有答案