【发布时间】:2015-05-04 11:23:40
【问题描述】:
我有 C# 中的申请表,我有以下代码来验证屏蔽文本框中的 IP 地址:
private void MainForm_Load(object sender, EventArgs e)
{
IPAdressBox.Mask = "###.###.###.###";
IPAdressBox.ValidatingType = typeof(System.Net.IPAddress);
IPAdressBox.TypeValidationCompleted += new TypeValidationEventHandler(IPAdress_TypeValidationCompleted);
}
void IPAdress_TypeValidationCompleted(object sender, TypeValidationEventArgs e)
{
if(!e.IsValidInput)
{
errorProvider1.SetError(this.IPAdressBox,"INVALID IP!");
}
else
{
errorProvider1.SetError(this.IPAdressBox, String.Empty);
}
}
在 IPAdres_TypeValidationComleted 函数中,如果语句为真,errorProvider1 会闪烁并给出“INVALID IP”消息,否则它应该会消失。问题是输入类型似乎总是无效,即使我输入了有效的 IP 地址。
【问题讨论】:
-
这里有一个解决方案:[Solution][1] [1]: stackoverflow.com/questions/7924000/…
标签: c# ip-address