C# winforms numericupdown control
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;
}
精彩评论