Casting inherited types

  • Thread starter Thread starter Jax
  • Start date Start date
J

Jax

I have made a class called MoneyBox, this inherits from
textbox and does little more except put and keep a "£" at
the front of it.
But on one of my forms I have a textbox that is sometimes
used for currency input but sometimes it isn't.

What i'd like to know is if it is possible to change the
type of this box at run time from events that are fired on
earlier parts on the form.
At present i'm just sticking with the textbox and adding
a "£" label infront of it when it should be a moneyBox,
which is a little cack.
It has to be able to switch to moneyBox to TextBox and
back, is this reasonable or not possible?

Many thanks for those that the time out to answer me.
jax
 
Hi Jax,

You could consider introducing a boolean property such as "MoneyModeEnabled"
which would turn your text box customizations on or off. An even better
solution would probably be to make this property of an enumerable type, say,
TextBoxStyle. This enumerable type would currently have two options -
Regular and Money, but could be extended to support more styles later.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

I have made a class called MoneyBox, this inherits from
textbox and does little more except put and keep a "£" at
the front of it.
But on one of my forms I have a textbox that is sometimes
used for currency input but sometimes it isn't.

What i'd like to know is if it is possible to change the
type of this box at run time from events that are fired on
earlier parts on the form.
At present i'm just sticking with the textbox and adding
a "£" label infront of it when it should be a moneyBox,
which is a little cack.
It has to be able to switch to moneyBox to TextBox and
back, is this reasonable or not possible?

Many thanks for those that the time out to answer me.
jax
 
Now that is a fine idea, and the concept of adding further
versions.
An almighty textbox would rise with the ability to
completely change it's functionality on the toggle of a
single property. Man it's a whole new world out there.
That is such a good idea. Thankyou.

jax
 
Back
Top