Articles → .NET → Controlling Numericupdown Buttons In Windows Form In .NET

Controlling Numericupdown Buttons In Windows Form In .NET





Picture showing the windows numeric up down control in .net
Click to Enlarge






Implementation




public class NumericUpDownExtendedClass: NumericUpDown {}




  1. UpButton() – Method invoked when up button is clicked.
  2. 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);





Posted By  -  Karan Gupta
 
Posted On  -  Friday, December 30, 2011

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250