Jeffrey Goines
Jeffrey Goines

Reputation: 955

How to Show Substitute Text for Some Values in NumericUpDown?

I made a dialog box that contains a numericupdown control, which has a range of -1~100

I want to show "infinite" for -1 instead of the raw value.

Upvotes: 0

Views: 957

Answers (2)

pescolino
pescolino

Reputation: 3123

To get the desired behaviour you have to create your own control that inherits from NumericUpDown. To change the text you can override the UpdateEditText method:

public class NumericUpDownEx : NumericUpDown
{
    public NumericUpDownEx()
    {
    }

    protected override void UpdateEditText()
    {
        if (Value < 0)
        {
            Text = "infinite";
        }
        else
        {
            base.UpdateEditText();
        }
    }
}

Upvotes: 1

Soner G&#246;n&#252;l
Soner G&#246;n&#252;l

Reputation: 98810

I'm not %100 sure but NumericUpDownAccelerationCollection class looks good for you.

Represents a sorted collection of NumericUpDownAcceleration objects in the NumericUpDown control.

Maybe something like;

NumericUpDown1.Accelerations.Items[0].Value = -1;
NumericUpDown1.Accelerations.Items[0].Text = "infinite";

Upvotes: 0

Related Questions