using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TaskManager
{
public static class ValidateHelper
{
static ValidateHelper()
{
IsErr = false;
}
public static bool IsErr
{
get;
set;
}
static ErrorProvider ep = new ErrorProvider();
public static bool Validate(this TextBox ctrl, System.Func<TextBox, bool> func, string errmsg)
{
if (!func(ctrl))
{
ep.SetError(ctrl, errmsg);
ctrl.Focus();
return !(IsErr=true);
}
return true;
}
public static bool Validate(this ListBox ctrl, System.Func<ListBox, bool> func, string errmsg)
{
if (!func(ctrl))
{
ep.SetError(ctrl, errmsg);
ctrl.Focus();
return !(IsErr = true);
}
return true;
}
public static void Clear()
{
ep.Clear();
IsErr = false;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TaskManager
{
public static class ValidateHelper
{
static ValidateHelper()
{
IsErr = false;
}
public static bool IsErr
{
get;
set;
}
static ErrorProvider ep = new ErrorProvider();
public static bool Validate(this TextBox ctrl, System.Func<TextBox, bool> func, string errmsg)
{
if (!func(ctrl))
{
ep.SetError(ctrl, errmsg);
ctrl.Focus();
return !(IsErr=true);
}
return true;
}
public static bool Validate(this ListBox ctrl, System.Func<ListBox, bool> func, string errmsg)
{
if (!func(ctrl))
{
ep.SetError(ctrl, errmsg);
ctrl.Focus();
return !(IsErr = true);
}
return true;
}
public static void Clear()
{
ep.Clear();
IsErr = false;
}
}
}
还是照样上两张图
用法
Code
相关文章链接:
C#学习使用ErrorProvider
http://www.cnblogs.com/sondy/archive/2006/04/16/376254.html
ErrorProvider的用法
http://www.cnblogs.com/sondy/archive/2006/04/16/376254.html
http://www.cnblogs.com/GrayZhang/archive/2008/09/01/1281526.html