Articles → .NET → Controlling Numericupdown Buttons In Windows Form In .NET
Controlling Numericupdown Buttons In Windows Form In .NET
Click to Enlarge
Implementation
public class NumericUpDownExtendedClass: NumericUpDown {}
- UpButton() – Method invoked when up button is clicked.
- DownButton() – Method invoked when down button is clicked.
public class NumericUpDownExtendedClass: NumericUpDown {
public override void DownButton() {}
public override void UpButton() {}
}
public class NumericUpDownExtendedClass: NumericUpDown {
public enum ControlMode {
Normal,
Reverse
}
public ControlMode ModeType {
get;
set;
}
public override void DownButton() {}
public override void UpButton() {}
}
public class NumericUpDownExtendedClass: NumericUpDown {
public enum ControlMode {
Normal,
Reverse
}
public ControlMode ModeType {
get;
set;
}
public override void DownButton() {
if (ModeType == ControlMode.Reverse) {
if (this.Value < Maximum) {
this.Value = this.Value + Increment;
((NumericUpDown)(this)).Text = this.Value.ToString();
}
}
else {
base.UpButton();
}
}
public override void UpButton() {
if (ModeType == ControlMode.Reverse) {
if (this.Value > Minimum) {
this.Value = this.Value - Increment;
((NumericUpDown)(this)).Text = this.Value.ToString();
}
}
else {
base.DownButton();
}
}
}
NumericUpDownExtendedClass extended = new NumericUpDownExtendedClass();
extended.ModeType = NumericUpDownExtendedClass.ControlMode.Reverse;
this.Controls.Add(extended);