Custom Control in TextBox Help?
-
05-07-2019 - |
Question
public partial class PreTextBox : TextBox
{
public PreTextBox()
{
InitializeComponent();
Text = PreText;
ForeColor = Color.Gray;
}
public string PreText
{
set;
get;
}
Text not set from PreText?
Solution
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;}
}
}
OTHER TIPS
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 :)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow