Hi Joe,
ValueChanged is fired when the Value property is changed, and any Text
changed at this point would get overwritten by the Control at a later stage.
You can, however, achieve the padding by overriding OnTextBoxChanged
protected override void OnTextBoxTextChanged(object source, EventArgs e)
{
Text = Value.ToString("00");
}
but you will lose the ability to manually enter the value.
If you change to Text = Text.PadLeft(2, '0'); you can manually enter a
value, but you are no longer limited to maxvalue, and the user input is not
logical, but you may be able to work something out.
--
Happy Coding!
Morten Wennevik [C# MVP]
"Joe Cool" wrote:
I am trying to force a numericupdown control to display leading zeros.
The maximum is less than 100, so the displayed value will always be a
two digit number or less. So I have overridden the OnValueChanged
Event with the following code;
protected override void OnValueChanged(EventArgs e)
{
base.OnValueChanged(e);
if (Value < 9)
Text = Value.ToString("00");
}
But it doesn't work. Can anyone spot the problem?