I'm writing a NumberTextbox
, which extends the standard Textbox class of Winforms. The class includes the following override for the Text property:
[DefaultValue("")]
public override string Text
{
get
{
return base.Text;
}
set
{
if (!IsNumber(value))
throw new FormatException();
base.Text = value;
}
}
The constructor does explicitly insert an empty string into the Text property. When I try to insert this textbox into a form using the designer, I get a FormatException
. Replacing the throw line with a return;
fixes the issue, but that seems to me to be wrong. Is there any better solution to this issue? Note that the IsNumber
method does return a true
for the empty string.