当前位置:网站首页>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

边栏推荐
猜你喜欢

StarRocks July Community Update

Bubble sort in c language structure

汇编题答案

unity2D横板游戏教程6-敌人AI以及受击动画

Dialog manager in the fourth chapter: the dialog message loop

10.预测房价:回归问题

How many moments have you experienced the collapse of electronic engineers?

【Harmony OS】【ARK UI】ETS 上下文基本操作

常见亲脂性细胞膜染料DiO, Dil, DiR, Did光谱图和实验操作流程

Interface test practice | Detailed explanation of the difference between GET / POST requests
随机推荐
MCM箱模型建模方法及大气O3来源解析
install ambari
Jmeter 模拟多用户登录的两种方法
2022 the first of the new league henan (4) : zhengzhou university of light industry G - maze
Oracle EMCC可以独立安装吗?还是必须安装到数据库服务器上?
t conditional judgment statement and if loop
Redis连接不上的报错解决方案汇总
excerpt from compilation book
测试人员的价值体现在哪里
工程制图第九章作业
多肽介导PEG磷脂——靶向功能材料之DSPE-PEG-RGD/TAT/NGR/APRPG
自组织是管理者和成员的双向奔赴
2022/08/02 Study Notes (day22) Multithreading
浏览器监听标签页关闭
unity2D横板游戏教程6-敌人AI以及受击动画
Assembly answers
JS底层手写
Problems that need to be solved for interrupting the system
LeetCode算法日记:面试题 03.04. 化栈为队
1.一个神经网络示例