I'm am trying to create a custom TextBox that display an empty string when it is disabled (Enabled = false). When I enable it again, it should display the last value. Also, the Text property should always return the real value, even if it's disabled.
Here is what I have so far, but it's not really working as I want.
Can you help me figure out what is wrong?
public class TestTextBox: System.Windows.Forms.TextBox
{
private string _text = string.Empty;
public new string Text
{
get
{
return _text;
}
set
{
_text = value;
base.Text = FormatValue(value);
}
}
protected override void OnEnabledChanged(EventArgs e)
{
base.OnEnabledChanged(e);
base.Text = FormatValue(_text);
}
private string FormatValue(string text)
{
if(this.Enabled == true)
{
return text;
}
else
{
return string.Empty;
}
}
}