私はVBを学んでいて、「ログイン」ボックスを作成しました。グーグルで小片を検索し、教科書を調べました。それが良いコードかどうかを見て、教えてほしいだけです...
私はそれをテストし、それは動作します..だから私はそれが「プロフェッショナル」または危険に見えることを知っていますか?
Public Class mainLogin
Private Sub mainLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' selects the username box when form loads
txtUsername.Select()
End Sub
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
If txtUsername.Text = "" Then
MessageBox.Show("Username field is empty.")
txtUsername.Select()
Exit Sub
End If
If txtPassword.Text = "" Then
MessageBox.Show("Password field is empty.")
txtPassword.Select()
Exit Sub
End If
If txtPassword.Text.Length < 8 Then
MessageBox.Show("Password length must be more then 8 characters.")
txtPassword.Clear()
Exit Sub
End If
If txtUsername.Text = "PavleS" Then
If txtPassword.Text = "Password11" Then
MessageBox.Show("Success!")
' Do something fancy here..
Else
MessageBox.Show("Bad Password!")
End If
Else
MessageBox.Show("Bad Username!")
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' clears username and password fields
txtPassword.Text = ""
txtUsername.Text = ""
End Sub
Private Sub txtPassword_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPassword.KeyDown
If e.KeyCode = Keys.Enter Then
' If Enter on the keyboard is pressed it will preform
' the same action as clicking the login button
btnLogin.PerformClick()
End If
End Sub
End Class