单行编辑控件不能有多行文本 matlab,WinForm控件之【TextBox】

//控件提示信息变量

string strUser = "长度不低于四个字符", strPwd = "长度不低于六个字符,由字母和数字组成";#region 用户密码控件设置提示信息相关事件

private void txt_user_Enter(objectsender, EventArgs e)

{

TextBox tb=(TextBox)sender;if(tb.Text.Equals(strUser))

{

tb.Text= string.Empty;

tb.ForeColor=System.Drawing.SystemColors.WindowText;

}

}private void txt_user_Leave(objectsender, EventArgs e)

{

TextBox tb=(TextBox)sender;if (string.IsNullOrWhiteSpace(tb.Text))

{

tb.Text=strUser;

tb.ForeColor=System.Drawing.SystemColors.ScrollBar;

}

}private void txt_pwd_Enter(objectsender, EventArgs e)

{

TextBox tb=(TextBox)sender;if(tb.Text.Equals(strPwd))

{

tb.Text= string.Empty;

tb.ForeColor=System.Drawing.SystemColors.WindowText;

tb.PasswordChar= '*';

}

}private void txt_pwd_Leave(objectsender, EventArgs e)

{

TextBox tb=(TextBox)sender;if (string.IsNullOrWhiteSpace(tb.Text))

{

tb.Text=strPwd;

tb.ForeColor=System.Drawing.SystemColors.ScrollBar;

tb.PasswordChar= '\0';

}

}#endregion

//登录

private void btn_login_Click(objectsender, EventArgs e)

{if (string.IsNullOrWhiteSpace(txt_user.Text) ||txt_user.Text.Equals(strUser))

{

MessageBox.Show("用户名不能为空!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);return;

}else{if (txt_user.Text.Length < 4)

{

MessageBox.Show("用户名长度不能低于四个字符!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);return;

}

}if (string.IsNullOrWhiteSpace(txt_pwd.Text) ||txt_pwd.Text.Equals(strPwd))

{

MessageBox.Show("密码不能为空!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);return;

}else{if (txt_pwd.Text.Length < 6)

{

MessageBox.Show("用户名长度不能低于六个字符!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);return;

}string strRegex = "[0-9]";if (!System.Text.RegularExpressions.Regex.IsMatch(txt_pwd.Text, strRegex))

{

MessageBox.Show("密码必须存在数字,请确认!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);return;

}

strRegex= "[a-zA-Z]";if (!System.Text.RegularExpressions.Regex.IsMatch(txt_pwd.Text, strRegex))

{

MessageBox.Show("密码必须存在字母,请确认!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);return;

}

}

MessageBox.Show("登录成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

}//退出

private void btn_exit_Click(objectsender, EventArgs e)

{this.Close();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值