Answer the question
In order to leave comments, you need to log in
How to bulk validate data from a userform?
winforms. there are 20 TextBoxes and 20 Labels nearby (they say what tb means).
All values are entered by the user. All values must be double.
I usually write something like this (probably shitty code):
private void TbLnsDist_TextChanged(object sender, EventArgs e)
{
string val = tbLnsDist.Text;
val = val.Replace(",", decimal_sep);
val = val.Replace(".", decimal_sep);
double number;
bool res = double.TryParse(val, out number);
if (res == false)
{
lbLnsDist.Text = "Введите число!";
lbLnsDist.ForeColor = Color.Red;
btnLnsCreate.Enabled = false;
}
else
{
lbLnsDist.Text = "Дистанция";
lbLnsDist.ForeColor = Color.Black;
btnLnsCreate.Enabled = true;
}
}
Answer the question
In order to leave comments, you need to log in
Write your own control that will only accept double and no checks are needed
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question