我的表单中有3个NumericUpDown
元素。这些元素通过它们的总和进行同步。例如sum是9个元素值是3,3,3,增量是2.当用户从第3个元素改变到第5个时,我们必须得到5,2,2。仅针对用户交互的NumericUpDown事件
对于同步,我曾尝试使用事件ValueChanged
和VisibleChanged
,但它们在我们进行编程修改或用户交互时正在工作。 我对每个元素都使用此方法,但对于此事件,此方法在结果值其他元素在代码中发生更改时再次开始更改。
private void numericUpDown1Change(object sender, EventArgs e)
{
int oldValue = Sum - (int)numericUpDown2.Value - (int)numericUpDown3.Value;
int average;
if ((int)numericUpDown1.Value - oldValue > 0)
{
average = ((int)numericUpDown1.Value - oldValue)/2;
numericUpDown2.Value = numericUpDown2.Value - average;
numericUpDown3.Value = numericUpDown3.Value - average;
}
else
{
average = (oldValue - (int)numericUpDown1.Value)/2;
numericUpDown2.Value = numericUpDown2.Value + average;
numericUpDown3.Value = numericUpDown3.Value + average;
}
}
我想使用事件,当用户单击向上或向下按钮时,或者用户输入新值时,什么工作。
我必须选择什么样的事件呢?
一些代码和你的实际问题会有所帮助。 –