C#winform设置回车事件
拿登录页设置为例:
输入用户名后回车,自动跳转到密码输入框,密码输入之后回车,触发点击登录事件。
用户名处代码:
private void txt_user_KeyPress(object sender, KeyPressEventArgs e) {
if (e.KeyChar == "")
this.txt_pass.Focus();
}
密码处代码:
private void txt_pass_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == "")
this.btn_login.PerformClick();
}
登录按钮事件:
private void btn_login_Click(object sender, EventArgs e) {
if (this.txt_user.Text.Trim() == "")
{
MessageBox.Show("请输入用户名!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.txt_user.Focus();
return;
}
if (this.txt_pass.Text.Trim() == "")
{
MessageBox.Show("请输入密码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.txt_pass.Focus();
return;
}
string username = this.txt_user.Text.Trim();
string password = MD5_class.GetMd5Hash(this.txt_pass.Text.Trim());
tb_user return_user = role_user_manage.check_login(username, password);
if (return_user == null)
{
MessageBox.Show("用户名或密码错误!请重新输入。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.txt_user.Focus();
return;
}
}
喜欢就联系我
以上是 C#winform设置回车事件 的全部内容, 来源链接: utcz.com/z/511250.html