Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String members and TextBox

Status
Not open for further replies.

alanmusician

Programmer
Jun 30, 2005
17
US
I'm new to C# and OO in general, and have a newbie question.

I have a class (ValidTextBox) inherited from TextBox that has various modifications to it, and one thing that I would like to do is make the Text control refer to a custom string class rather than string. How can this be accomplished?

What I'm trying to do is add a ToProper to my ValidTextBox.Text. I want to be able to say ValidTextBox.Text.ToProper(); and have the text in the box turn to proper case. I've already written the ToProper method as a member of EntryString (which inherits from string), but I'm not sure how to get my ValidTextBox class to use it instead of string.

Thanks in advance,
--Alan
 
I don't think that is possible until we get to VS 2008 and you can have an extention method that adds ToProper to the string class.

And in 2005 string is a sealed class so that you can't inherit from it so I'm not sure exactly what you did. Please post code if you can.

I might just add the method to your textbox with a good name on it like

ValidTextBox.ValueToProper();
 
That sounds interesting. :)

Maybe you can try shadowing the Text property?
Code:
    // Declare a private field for ValidTextBox
    private YourString _yourstring;
    
    // Define your own Text property...
    public new YourString Text
    {
        get{ return _yourstring; }
        set{ 
             base.Text = value.ToString();
             _yourstring = value;
           }
    }

Or, just add another property that returns EntryString.

My 2cents. [wink]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top