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

边栏推荐
- 好消息!北京、珠海PMP考试时间来啦
- Assembly answers
- Oracle EMCC可以独立安装吗?还是必须安装到数据库服务器上?
- 自组织是管理者和成员的双向奔赴
- Interface testing framework combat (3) | JSON request and response assertion
- Shell之条件语句
- closures in js
- 【Harmony OS】【ArkUI】ets开发 图形与动画绘制
- Kotlin-Flow common encapsulation class: the use of StateFlow
- OpenFOAM extracts equivalency and calculates area
猜你喜欢
随机推荐
t conditional judgment statement and if loop
How to prepare for the test interface test data
【Harmony OS】【ARK UI】Date 基本操作
Assembly answers
StarRocks 7 月社区动态
Windows 安装PostgreSQL
接口测试 Mock 实战(二) | 结合 jq 完成批量化的手工 Mock
mysql 创建索引的三种方式
Oracle EMCC可以独立安装吗?还是必须安装到数据库服务器上?
社交电商:链动2+1模式,为什么能在电商行业生存那么久?
【开发者必看】【push kit】推送服务服务典型问题合集2
How to use the interface management tool YApi?Beautiful, easy to manage, super easy to use
mysql bool盲注
CobalStrike(CS)基础超级详细版
接口测试框架实战(三)| JSON 请求与响应断言
GIS数据漫谈(六)— 投影坐标系统
SM30 表维护视图数据保存前 数据校验事件
2022河南萌新联赛第(四)场:郑州轻工业大学 G - 迷宫
rosbag工具plotjuggler无法打开rosbag的问题
Concepts and Methods of Exploratory Testing









