groupBox中控件,及空间中的控件 的文本框内容的输入进行判断

groupBox中控件,及空间中的控件 的文本框内容的输入进行判断
一:groupBox1中的文本框内容只能为正整数,null,空格。
1.对groupBox1中的控件进行遍历
2.判断是否是文本框
3.对文本框的去空的每个字符进行判断(是否为为数字)——不为数字弹框,结束程序
4.判断程序为空,或者c.Text.LastIndexOf(” “)到 空格——弹框,结束程序
foreach (Control c in groupBox1.Controls)
{
if (c is TextBox)
{
for (int i = 0; i < c.Text.Trim().Length; i++)
{
if (!char.IsNumber(c.Text.Trim()[i]))
{
MessageForm messageForm = new MessageForm(“变量必须为数字!”);
messageForm.ShowDialog();
return;
}
}
if (c.Text == string.Empty || c.Text.LastIndexOf(” “) != -1)
{
MessageForm messageForm = new MessageForm(“不能为空!”);
messageForm.ShowDialog();
return;
}
}
}
二:groupBox2中的控件中的文本框内容为正负数/小数,null,空格。
1.对groupBox2中的控件进行遍历,的c
2.再对c,进行遍历
3.判断是否有文本框
4.是文本框:文本框内容为null/空格,结束本次循环(保证可以输入null空格)
5.然后,正则表达式:[-+][0-9][.][0-9]+|[-+][1-9][0-9]*|^[0]$ ——使文本框内容为正负整数/小数
6.Regex.IsMatch(需要判断的字符a, 正则式b)——相等a,b相同返回ture
foreach (Control c1 in groupBox2.Controls)//阈值设置
{
foreach (Control c in c1.Controls)
{
if (c is TextBox)
{
if (c.Text == string.Empty || c.Text.LastIndexOf(” “) != -1)
{
continue;
}
else
{
string pattern = @”[-+][0-9][.][0-9]+|[-+][1-9][0-9]*|^[0]$”;
bool result = false;
result = System.Text.RegularExpressions.Regex.IsMatch(c.Text.Trim(), pattern);
if (!result)
{
MessageForm messageForm = new MessageForm(“变量必须为数字!”);
messageForm.ShowDialog();
return;
}
}
}
}
}
三,读取
1.先判断是否为空
2.不为空转换为double类型都取出来
if (iniFiles.ReadString(“Threshold”, “TempLowerThreshold”, “”) != “” && (iniFiles.ReadString(“Threshold”, “TempUpperThreshold”, “”) != “”))
{
TempLowerThreshold = double.Parse(iniFiles.ReadString(“Threshold”, “TempLowerThreshold”, “”));
TempUpperThreshold = double.Parse(iniFiles.ReadString(“Threshold”, “TempUpperThreshold”, “”));//温度
}