Property renaming?

  • Thread starter Thread starter Johnny Jörgensen
  • Start date Start date
J

Johnny Jörgensen

Is there any way of renaming the properties of standard controls.

I want to create a TextBox control inherited from a normal textbox control,
but I want to use the property for something else. Let's say the program
sets the Text property to "Mickey", then I want the TextBox to Show
"Donald"?

And if the user enters "Donald" into the textbox and I query the TextBox's
text property, I want to read "Mickey"

Is that possible?

As I see it, it would entail renaming the text property, because the new
Text property you create would somehow have to link to the "real" text
property?!?!?

TIA,
Johnny J.
 
Johnny Jörgensen said:
Is there any way of renaming the properties of standard controls.

I want to create a TextBox control inherited from a normal textbox
control, but I want to use the property for something else. Let's say the
program sets the Text property to "Mickey", then I want the TextBox to
Show "Donald"?

And if the user enters "Donald" into the textbox and I query the TextBox's
text property, I want to read "Mickey"

Is that possible?

As I see it, it would entail renaming the text property, because the new
Text property you create would somehow have to link to the "real" text
property?!?!?

You don't have to rename the property, you just override it and do the
conversions inside it before calling the base property:

public overrides string Text
{
get
{
if (base.Text=="Donald") return "Mickey";
else return base.Text;
}
set
{
if (value=="Mickey") base.Text="Donald";
else base.Text = value;
}
}
 
Back
Top