当前位置:网站首页>WinForm的控件二次开发
WinForm的控件二次开发
2022-08-03 04:19:00 【ViperL1】
一、输入栏非空验证
①首先要新建一个类库,然后在其中额外新建组件类

②在类库中添加控件命名空间的引用(System.Windows.Forms)

③将基类改为需要继承的控件(如TextBox)
public partial class SuperTextBox : TextBox④在编辑区拖放errorProvider

⑤编写警告方法并关联错误提示
public bool CheckEmpty()
{
if(this.Text=="")
{
this.errorProvider.SetError(this,"不能为空"); //从属的组件,提醒内容
return true
}
else
{
this.errorProvider.SetError(this,empty);
return false;
}
}⑥直接在项目中以普通控件的方法应用即可

同时也必须在函数体中调用CheckEmpty();才能使其生效。
二、利用正则表达式实现复杂验证
基于上述项目,重新编写验证方法
public bool BeginCheckData(string regularExpress, string errorMsg)
{
if(CheckEmpty() == false)
return false;
Regex objRegex = new Regex(regularExpress,RegexOptions.IgnoreCase); //忽略大小写
if(!objRegex.IsMatch(this.Text))
{
this.errorProvider.SetError(this,"验证不通过");
return true
}
else
{
this.errorProvider.SetError(this,empty);
return false;
}
}三、其他方案调用自定义控件
将控件方案生成的.dll代码移动到需要调用的项目之中,然后在工具箱中进行引用

边栏推荐
- 中断系统需要解决的问题
- 肖sir___面试就业课程____性能测试
- 高等代数_证明_矩阵乘以自身的转置的特征值不小于0
- lc marathon 8.2
- 2022河南萌新联赛第(四)场:郑州轻工业大学 G - 迷宫
- 我将GuiLite移植到了STM32F4开发板上
- I ported GuiLite to STM32F4 board
- The flink sql task is changed, and after adding several fields to the sql, an error occurs when restoring from the previously saved savepoint.
- 正则表达式绕过
- 肖sir___面试就业课程____app
猜你喜欢
随机推荐
接口和协议
DMA 的工作方式
2022河南萌新联赛第(四)场:郑州轻工业大学 G - 迷宫
刚上线就狂吸70W粉,新型商业模式“分享购”来了,你知道吗?
Mysql如何建立索引实现语句优化
How many moments have you experienced the collapse of electronic engineers?
【STM32】入门(三):按键使用-GPIO端口输出控制
9.新闻分类:多分类问题
记录一些遇见的bug——mapstruct和lombok同时使用时,转换实体类时数据丢失问题
SkiaSharp 之 WPF 自绘 五环弹动球(案例版)
Shenzhen Offline Registration|StarRocks on AWS: How to conduct rapid and unified analysis of real-time data warehouses
v-on指令:为元素绑定事件
The flink sql task is changed, and after adding several fields to the sql, an error occurs when restoring from the previously saved savepoint.
【无标题】2022-7-24
这个困扰程序员50年的问题,终于要被解决了?
ORACLE中文乱码
工程制图第九章作业
肖sir___面试就业课程____性能测试
Assembly answers
SMP 需要考虑的事情









