当前位置:网站首页>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代码移动到需要调用的项目之中,然后在工具箱中进行引用

边栏推荐
猜你喜欢
随机推荐
ORACLE中文乱码
肖sir ——自动化讲解
SeleniumWebDriver扩展插件开发
(2022牛客多校五)G-KFC Crazy Thursday(二分+哈希)
Live | StarRocks technology insider: low base dictionary global optimization
Shenzhen Offline Registration|StarRocks on AWS: How to conduct rapid and unified analysis of real-time data warehouses
6.神经网络剖析
I ported GuiLite to STM32F4 board
移动流量的爆发式增长,社交电商如何选择商业模式
移植RT-Thread编译报错thumb conditional instruction should be in IT block
GD32学习笔记(3)NAND Flash管理
v-text指令:设置标签内容
【无标题】2022-7-24
普乐蛙VR台风体验馆厂家VR防震减灾模拟VR沉浸式体验设备
Smart fitness gesture recognition: PP - TinyPose build AI virtual trainer!
2022 Henan Mengxin League Game (4): Zhengzhou University of Light Industry E - Sleep Well
3.张量运算
Oracle EMCC可以独立安装吗?还是必须安装到数据库服务器上?
ScanNet数据集讲解与点云数据下载
vscode access denied to unins000.exe









