Having text inside NumericUpDown control, after the number

Saeid Yazdani picture Saeid Yazdani · May 7, 2011 · Viewed 14.4k times · Source

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.

Answer

Cody Gray picture Cody Gray · May 7, 2011

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