views:

47

answers:

2
public partial class PreTextBox : TextBox
{
    public PreTextBox()
    {
        InitializeComponent();
        Text = PreText;
        ForeColor = Color.Gray;
    }
    public string PreText
    {
        set;
        get;
    }

Text not set from PreText?

A: 

Your code only does it once, on the constructor. You will have to write a setter for your PreText property to set the Text property as well.

Or you could just use the Text property on the TextBox that you're inheriting from and be done with it :)

popester
A: 

Try the following:

public partial class PreTextBox : TextBox
{
    public PreTextBox()
    {
        InitializeComponent();
        Text = PreText;
        ForeColor = Color.Gray;
    }
    public string PreText
    {
        set{Text = value;} 
        get{return Text;}
    }
}
Wael Dalloul
get{return Text;}
monkey_boys
private string _p; public string PreText { set { Text = value; _p = value; } get { return _p; } }
monkey_boys