开发者

Custom Control in TextBox Help?

public partial class PreTex开发者_开发问答tBox : TextBox
{
    public PreTextBox()
    {
        InitializeComponent();
        Text = PreText;
        ForeColor = Color.Gray;
    }
    public string PreText
    {
        set;
        get;
    }

Text not set from PreText?


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;}
    }
}


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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜