我正在制作 ac# 登录系统,与 MySQL 连接,目前进展顺利。我怎样才能使这段代码更好?它的代码太多了。
if (string.IsNullOrEmpty(textBoxUsername.Text))
{
//Focus box before showing a message
textBoxUsername.Focus();
MessageBox.Show("Enter your username", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
//Focus again afterwards, sometimes people double click message boxes and select another control accidentally
textBoxUsername.Focus();
return;
}
else if (string.IsNullOrEmpty(textBoxPassword.Text))
{
textBoxPassword.Focus();
MessageBox.Show("Enter your password", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
textBoxPassword.Focus();
return;
}