I created custom control PlaceHolderTextBox with some properties.
Here is my code:
class PlaceHolderTextBox:TextBox
{
public string PlaceHolderText { get; set; }
public Color PlaceHolderColor { get; set; }
public Font PlaceHolderFont { get; set; }
public Color StandardColor { get; set; }
public PlaceHolderTextBox()
{
GotFocus += OnGetFocus;
LostFocus += OnLostFocus;
TextChanged += OnTextChanged;
Text = PlaceHolderText;
ForeColor = PlaceHolderColor;
Font = PlaceHolderFont;
}
private void OnGetFocus(object sender,EventArgs e)
{
if (this.Text == this.PlaceHolderText)
{
ForeColor = StandardColor;
Text = "";
}
}
private void OnLostFocus(object sender, EventArgs e)
{
if (this.Text == "")
{
ForeColor = PlaceHolderColor;
Text = PlaceHolderText;
}
}
}
And when i start program, i get empty textbox.
I think reason of that behaviour is that on time constructor executes, the properties are empty, but im not sure.
Also, i want to make events when i change these custom properties.
Is that possible?