C#的WinForms NumericUpDown控件 [英] C# winforms numericupdown control
本文介绍了C#的WinForms NumericUpDown控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的NumericUpDown控件。当值编程分配或用户更改了值,触发ValueChanged事件。
I am using numericupdown control. When a value is assigned programmatically or 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 it can be done?
推荐答案
在TheVillageIdiot的回答大厦...你可以创建可重用的子类:
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;
}
}
}
这篇关于C#的WinForms NumericUpDown控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文