2015-05-29 28 views
-2

我寫的程序有一個「numericUpDow」。我的numericUpDown有下一個配置:數字在c中向下#

numericUpDown.Maximun = 5; 
numericUpDown.Minimun = 0; 

我希望我可以選擇數字從0到5減2,這可能嗎?

+3

確定。那麼你的問題是什麼? – 2015-05-29 11:14:47

+0

你的意思是「不包括2」? –

回答

0

添加表單級變量:

decimal oldValue = 0; 

綁定到ValueChanged事件:

numericUpDown.ValueChanged += numericUpDown_ValueChanged; 

numericUpDown_ValueChanged代碼:

void numericUpDown_ValueChanged(object sender, EventArgs e) 
{ 
    NumericUpDown ctrl = sender as NumericUpDown; 
    if (ctrl.Value == 2) 
    { 
     // bad, very very bad 
     ctrl.Value = oldValue > 2 ? 1 : 3; 
    } 
    oldValue = ctrl.Value; 
}