开发者

help me to cheat with numericUpDown1_ValueChanged event

I have a Form and numericupdown control located on it. I want that in some conditions (_condition1) user cannot be able to change a value of numericupdown control. How can I do it ? I wrote some code but it works twice (double time).

class Form1 : Form
{
    bool _condition1;

    int _previousValue;

    void numericUpDown1_ValueChanged(object sender, EventArgs e)
    {
           if(_condition1)
           {
                 numericUpDown1.Value = (decimal)_previousValue;
           }
           else
           {
                 _previousValue = (int)numericUpDow开发者_如何学Gon1.Value;
           }
    }
}

Control must be enable.


numericUpDown1.ReadOnly = true;

?

.... edit: ..........

Another (ugly) solution would be to remove the event, change the value, and add the event again ..

numericupdown1.ValueChanged -= new EventHandler ....
numericupdown1.Value = value;
numericupdown1.ValueChanged += new EventHandler ....


Have you tried using the Validating event?

EDIT #1 Have you tried the Leave event?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜