In C# WinForms desktop application I use 2 interdependent numericUpDown1 min and numericUpDown2 max value numericUpDown controls:
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
if (numericUpDown1.Value <= numericUpDown2.Value)
{
min = (int)numericUpDown1.Value;
}
else
{
numericUpDown1.Value = min - 1;
}
}
private void numericUpDown2_ValueChanged(object sender, EventArgs e)
{
if (numericUpDown2.Value >= numericUpDown1.Value)
{
max = (int)numericUpDown2.Value;
}
else
{
numericUpDown2.Value = max + 1;
}
}
with using of ReadOnly = true; to avoid making the maximal number less than minimal manually from numericUpDown input.:
min = 20;
max = 1999;
numericUpDown1.Value = min;
numericUpDown2.Value = max;
numericUpDown1.ReadOnly = true;
numericUpDown2.ReadOnly = true;
numericUpDown1.Increment = 1;
numericUpDown2.Increment = 1;
numericUpDown1.Maximum = 2000;
numericUpDown1.Minimum = 1;
numericUpDown2.Maximum = 2000;
numericUpDown2.Minimum = 1;
but I use a big range from 1 to 2000, and want to allow the user to change the number of numericUpDown manually with ReadOnly = false;.
I'm trying to figure out, how to control the user input condition with ReadOnly = false; of numericUpDown to avoid the input of maximal number less than minimal or minimal bigger then maximal.
MinimumandMaximumproperties