Search code examples
c#.netwinformsstringnumericupdown

Having text inside NumericUpDown control, after the number


Is it possible in WinForms to show a text inside a NumericUpDown control? For example I want to show the value in my numericupdown control is micro ampers so it should be like "1 uA".

Thanks.


Solution

  • There's no such functionality built into the standard control. However, it's fairly easy added by creating a custom control that inherits from the NumericUpDown class and overrides the UpdateEditText method to format the number accordingly.

    For example, you might have the following class definition:

    public class NumericUpDownEx : NumericUpDown
    {
        public NumericUpDownEx()
        {
        }
    
        protected override void UpdateEditText()
        {
            // Append the units to the end of the numeric value
            this.Text = this.Value + " uA";
        }
    }
    

    Or, for a more complete implementation, see this sample project: NumericUpDown with unit measure