使用ErrorProvider组件验证文本框输入
2024-08-27 11:39:16
实现效果:
知识运用:
ErrorProvider组件的BlinkStyle属性 //指示错误图标的闪烁时间
public ErrorBlinkStyle BlinkStyle{ get;set; }
BlinkRate属性 //图标的闪烁频率 (毫秒为单位)
public int BlinkRate {get; set;}
SetError方法 //将Error属性设置为指定的TextWriter对象
public static void SetError(TextWriter newError)
TextBox文本框的Validating事件 //在控件正在发生验证时发生
public event CancelEventHandler Validating
实现代码:
string strA = null;
string strB = null; private void txtPwd_Validating(object sender, CancelEventArgs e)
{
if (txtPwd.Text != "microsoft")
{
errorProvider1.SetError(txtPwd, "密码错误");
}
else
{
errorProvider1.SetError(txtPwd, ""); //不显示任何内容
strB = txtPwd.Text;
}
} private void txtUser_Validating(object sender, CancelEventArgs e)
{
if (txtUser.Text != "soft")
{
errorProvider1.SetError(txtUser, "用户名错误");
}
else
{
errorProvider1.SetError(txtUser, ""); //不显示任何内容
strA = txtUser.Text;
}
}
最新文章
- Gollum 安装笔记
- Linux中常用操作命令
- 手把手教你搭建SpringMVC——最小化配置
- Undefined symbols for architecture x86_64: ";_OBJC_CLASS_$_GiftAnimationView";
- androidd 程序默认安装位置和数据存储位置(公用和私用)
- 单元测试中使用Moq对EF的DbSet进行mock
- 【网络流24题】No.7 试题库问题 (最大流,二分图多重匹配)
- 交叉编译:cannot find /lib/libc.so.6 collect2: ld returned 1 exit status
- 在PyQt4中使用matplotlib
- 关于JAVA中split方法使用竖线异常的问题
- leetcode371
- VLAN之间单臂路由通信
- 3分钟学会做智能插座(DIY)
- git根据用户过滤提交记录
- MySQL Split 函数
- mac下/usr/local/bin No such file or directory问题解决
- PR使用技巧
- 【MySQL学习杂记】 2017年7月13日
- Linux下 sleep函数的注意事项
- Windbg查看w3wp进程占用的内存及.NET内存泄露,死锁分析
热门文章
- Java8函数式接口之Predicate<;T>;
- Guid.NewGuid().ToString()的几种格式 (转)
- 集成Python Shell
- encodeURI和uncodeURIComponent的介绍
- AI决策算法 之 GOAP (一)
- 洛谷P3405 [USACO16DEC]Cities and States省市
- 平衡的阵容 st表学习
- Django一些鲜为人知的操作
- Avito Cool Challenge 2018-A. Definite Game(思维题)
- Spring boot中应用jpa jpa用法