3

当用户输入上面的值numericUpDown.Maximum时,控件的值会自动设置为最大值。我想在发生这种情况时显示一个 MessageBox,但我不能这样做,因为control.Value并且已经包含了在引发事件control.Text时自动设置的值最大值。Validating

private void numericUpDown_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
       NumericUpDown control = sender as NumericUpDown;
       decimal newValue = control.Value;

       // decimal newValue;
       // decimal.TryParse(control.Text, out newValue)

       if (newValue > control.Maximum || newValue < control.Minimum)
       {
            // MessageBox

        }

}

谢谢

4

1 回答 1

3

通过用消息框拍打她来唠叨用户并不能形成最好的用户界面。但是您只需将最小值和最大值设置为更小/更大并检查 ValueChanged 事件中的值即可轻松完成。

于 2010-05-21T20:15:30.133 回答