2009-10-22 94 views
0
public partial class PreTextBox : TextBox 
{ 
    public PreTextBox() 
    { 
     InitializeComponent(); 
     Text = PreText; 
     ForeColor = Color.Gray; 
    } 
    public string PreText 
    { 
     set; 
     get; 
    } 

未在PreText中设置文字?TextBox帮助中的自定义控件?

+0

不知道你真正想实现。 – NinethSense 2009-10-22 07:41:33

回答

1

尝试以下操作:

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

得到{return Text;} – 2009-10-22 08:04:01

+0

private string _p; public string PreText { set { Text = value; _p = value; } 得到 { return _p; } } – 2009-10-22 08:04:47

0

您的代码只在构造函数中执行一次。你将不得不为你的PreText属性编写setter来设置Text属性。

或者你可以只使用Text属性上,你继承,并用它做文本框:)