'添加好控件,把代码复制到窗体模块可以了吧。
'label1,Label2,Text1
'Command1:确定,command2:重输
Private Sub Form_Load()
Text1.PasswordChar = "*"
Text1.MaxLength = 6
Command1.Enabled = False
Command2.Visible = False
Label2.Visible = False
End Sub
Private Sub Command1_Click()
If Text1.Text = "123456" Then
Label2.ForeColor = vbBlue
Label2.Caption = "欢迎进入应用程序!"
Else
Label2.ForeColor = vbRed
Label2.Caption = "密码错误!"
End If
Label2.Visible = True
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Command1.Enabled = False
Command2.Visible = False
End Sub
Private Sub Text1_Change()
If Text1.Text <> "" Then
Command1.Enabled = True
Command2.Visible = True
Else
Label2.Visible = False
Command1.Enabled = False
Command2.Visible = False
End If
End Sub