How to override the Text property of Control class?
-
:confused:I create a UserControl and add a TextBox into the control.I want to have a Text property,in order that set or get the TextBox.Text.But I know Control class had the same property,and then I key the code that in list -------------------- public partial class UserControl1 : UserControl { string _t; [Browsable(true)] public override string Text { get { this.textBox1.Text = _t; return _t; } set { _t = value; this.textBox1.Text = _t; } ... } ----------------------------- When I test the control,I modify the Text property in the Properties Designer of the VS.NET 2005,The Control.Text get a value.But I open the method InitializeComponent() ,I can not find the code that initialize control.Text. So,When the test application running,The value that Text property of the TextBox in the control is lost. Can you tell me why? How to deal with it? Thanks a lot!
-
:confused:I create a UserControl and add a TextBox into the control.I want to have a Text property,in order that set or get the TextBox.Text.But I know Control class had the same property,and then I key the code that in list -------------------- public partial class UserControl1 : UserControl { string _t; [Browsable(true)] public override string Text { get { this.textBox1.Text = _t; return _t; } set { _t = value; this.textBox1.Text = _t; } ... } ----------------------------- When I test the control,I modify the Text property in the Properties Designer of the VS.NET 2005,The Control.Text get a value.But I open the method InitializeComponent() ,I can not find the code that initialize control.Text. So,When the test application running,The value that Text property of the TextBox in the control is lost. Can you tell me why? How to deal with it? Thanks a lot!