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

边栏推荐
猜你喜欢

移动流量的爆发式增长,社交电商如何选择商业模式

【uni-APP搭建项目】

普乐蛙VR台风体验馆厂家VR防震减灾模拟VR沉浸式体验设备

链动2+1模式简单,奖励结构丰厚,自主裂变?

接口管理工具YApi怎么用?颜值高、易管理、超好用

Two ways to simulate multi-user login in Jmeter

BIOTIN ALKYNE CAS:773888-45-2价格,供应商

深圳线下报名|StarRocks on AWS:如何对实时数仓进行极速统一分析

Concepts and Methods of Exploratory Testing

2022/08/02 学习笔记 (day22) 多线程
随机推荐
私域流量时代来临,电商企业如何布局?
接口测试框架实战(三)| JSON 请求与响应断言
9.新闻分类:多分类问题
excerpt from compilation book
5.回顾简单的神经网络
传统企业如何转型社交电商,泰山众筹的玩法有哪些?
online test paper concept
mysql 创建索引的三种方式
超好用的画图工具推荐
刚上线就狂吸70W粉,新型商业模式“分享购”来了,你知道吗?
Live | StarRocks technology insider: low base dictionary global optimization
Dialog manager in the fourth chapter: the dialog message loop
mysql bool盲注
Bubble sort in c language structure
记录一些遇见的bug——mapstruct和lombok同时使用时,转换实体类时数据丢失问题
Two ways to simulate multi-user login in Jmeter
2.何为张量
【Harmony OS】【ARK UI】Date 基本操作
2022 the first of the new league henan (4) : zhengzhou university of light industry G - maze
技术分享 | 接口自动化测试中如何对xml 格式做断言验证?