Reputation: 88
I want to take 4-digit value from Users using numericUpDown. So, I want to set up "0000" instead "0" to remember them to enter 4-digit.
I am programming WinForm With C#.
I am waiting your help.
Upvotes: 1
Views: 1400
Reputation: 39122
Just override UpdateEditText and format your value...
public class MyNumericUpDown : NumericUpDown
{
protected override void UpdateEditText()
{
this.Text = this.Value.ToString().PadLeft(4, '0');
}
}
Rebuild and your new control should appear in the top of your toolbox.
Upvotes: 6
Reputation: 23
As others have said, "0000" is a string rather than a number, so that won't really work for a NumericUpDown. The closest solution I can think of would be to create 4 separate NumericUpDowns that accept values 0 through 9 and convert that to your number. Then you could get your 0 0 0 0 to appear and people could move the individual digits up and down. Otherwise I think you would have to use a control that uses strings instead of numbers.
Upvotes: 0