开发者

C# winforms numericupdown control

开发者 https://www.devze.com 2022-12-21 15:09 出处:网络
I am using the numericupdown control. When a value is assigned programmatically 开发者_如何学JAVAor user changes the value, the ValueChanged event is triggered.

I am using the numericupdown control. When a value is assigned programmatically 开发者_如何学JAVAor user changes the value, the ValueChanged event is triggered.

I want the event to be triggered only when the user changes the values and not when I set the minimum and maximum values. How can it be done?


Building on TheVillageIdiot's answer... You could create a reusable subclass like:

public sealed class MyNumericUpDown : NumericUpDown {

    private bool suppress;

    protected override void OnValueChanged(EventArgs e) {
        if (!suppress) {
            base.OnValueChanged(e);
        }
    }

    public void SetRange(decimal min, decimal max) {
        suppress = true;
        try {
            Minimum = min;
            Maximum = max;
        }
        finally {
            suppress = false;
        }
    }

}


Try something like this:

var changeFromCode = false;

void abc()
{
   // This is where you change value in code.
   changeFromCode = true;
   ud1.Value = 15;
   changeFromCode = false;
}

// Sorry, I am not sure about handler signatures
void UpDownValueChanged(object sender, EventArgs e)
{
   if (changeFromCode)
       return;
}
0

精彩评论

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

关注公众号