当前位置:网站首页>Secondary development of WinForm controls
Secondary development of WinForm controls
2022-08-03 04:40:00 【ViperL1】
One, the input field is not empty verification
① First of all, create a class library, and then add an additional component class
in it
②Add a reference to the control namespace in the class library (System.Windows.Forms)

3 Change the base class to the control that needs to be inherited (such as TextBox)
public partial class SuperTextBox : TextBox④ Drag and drop errorProvider
in the editing area
⑤ Write a warning method and associate an error message
public bool CheckEmpty(){if(this.Text==""){this.errorProvider.SetError(this,"cannot be empty"); //Subordinate component, reminding contentreturn true}else{this.errorProvider.SetError(this,empty);return false;}}⑥ ⑥It can be applied directly in the project by the method of ordinary controls

also must be called CheckEmpty(); in the function body for it to take effect.
Second, use regular expressions to achieve complex verification
Based on the above project, rewrite the verification method
public bool BeginCheckData(string regularExpress, string errorMsg){if(CheckEmpty() == false)return false;Regex objRegex = new Regex(regularExpress,RegexOptions.IgnoreCase); //Ignore caseif(!objRegex.IsMatch(this.Text)){this.errorProvider.SetError(this, "verification failed");return true}else{this.errorProvider.SetError(this,empty);return false;}}Three, other programs call custom controls
Move the .dll code generated by the control scheme to the project that needs to be called, and then reference it in the toolbox

边栏推荐
- C#异步和多线程
- 1.一个神经网络示例
- MySQL 入门:Case 语句很好用
- Flink状态
- Record some bugs encountered - when mapstruct and lombok are used at the same time, the problem of data loss when converting entity classes
- 安装ambari
- How to use the interface management tool YApi?Beautiful, easy to manage, super easy to use
- 工程制图点的投影练习
- 5.回顾简单的神经网络
- Interface test framework combat (1) | Requests and interface request construction
猜你喜欢
随机推荐
接口测试框架实战(二)| 接口请求断言
8.电影评论分类:二分类问题
JS底层手写
我将GuiLite移植到了STM32F4开发板上
汇编题答案
install ambari
IO进程线程->线程->day5
Shell条件语句判断
工程制图点的投影练习
接口测试框架实战 | 流程封装与基于加密接口的测试用例设计
那些让电子工程师崩溃瞬间,你经历了几个呢?
flink sql任务变更,在sql里面增加几个字段后,从以前保存的savepoint恢复启动出错。
2022 Henan Mengxin League Game (4): Zhengzhou University of Light Industry E - Sleep Well
v-on指令:为元素绑定事件
探索性测试的概念及方法
mysql bool blind
online test paper concept
Redis缓存雪崩、缓存穿透、缓存击穿
Test drive: project management module - curd development project
Windows 安装PostgreSQL









