2009-10-22 61 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屬性上,你繼承,並用它做文本框:)