C#【控件篇】组件ErrorProvider的使用
2023-09-11 14:15:48 时间
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text.Length < 8 || textBox1.Text.Length > 15)
{
errorProvider1.SetError(textBox1, "请输入8-15位字母和数字");
errorProvider1.Icon = new Icon(@"D:\Desktop\WindowsFormsApp1\WindowsFormsApp1\bin\Debug\error.ico");
}
else
{
errorProvider1.SetError(textBox1,"");
errorProvider1.Icon = new Icon(@"D:\Desktop\WindowsFormsApp1\WindowsFormsApp1\bin\Debug\ok.ico");
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (textBox2.Text.Length < 8 || textBox2.Text.Length > 15)
{
errorProvider1.SetError(textBox2, "请输入8-15位字母和数字");
errorProvider1.Icon = new Icon(@"D:\Desktop\WindowsFormsApp1\WindowsFormsApp1\bin\Debug\error.ico");
}
else
{
errorProvider1.SetError(textBox2, "符合要求");
errorProvider1.Icon = new Icon(@"D:\Desktop\WindowsFormsApp1\WindowsFormsApp1\bin\Debug\ok.ico");
}
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
if (textBox3.Text!=textBox2.Text)
{
errorProvider1.SetError(textBox3, "两次输入的密码不一致");
errorProvider1.Icon = new Icon(@"D:\Desktop\WindowsFormsApp1\WindowsFormsApp1\bin\Debug\error.ico");
}
else
{
errorProvider1.SetError(textBox3, "通过验证");
errorProvider1.Icon = new Icon(@"D:\Desktop\WindowsFormsApp1\WindowsFormsApp1\bin\Debug\ok.ico");
}
}
}
}
界面控件如下:
相关文章
- C# 正则表达式大全
- C#之语言详述
- C#.NET常见问题(FAQ)-方法参数带ref是什么意思
- .net(C#)访问Oracle数据库的几种免安装组件的对比
- C#中巧用#if DEBUG 进行调试
- 给 C# 开发者的代码审查清单
- C# Winform播放多媒体文件 [AudioVideoPlayback ]
- C# FTP上传下载(支持断点续传)
- C#中StreamReader读取中文出现乱码
- [转] 使用C#开发ActiveX控件
- C# 打开指定路径下文件
- Atitit. c# 语法新特性 c#2.0 3.0 4.0 4.5 5.0 6.0 attilax总结 1. 版本历史1 1.1. C# 1.0-纯粹的面向对象2 1.2. C# 2.0
- C# 基本语法
- 【设计模式】访问者模式(C#)