I searched on the Internet how to make a placeholder for TextBox but did not find a compact code and decided to invent another bicycle.
The form has a textbox in the properties is Text = "Placeholder Text" and Tag = "Placeholder Text", then I hang up an event handler
Determine the colors of the placeholder
Color LeaveColor = Color.FromArgb(160, 160, 160); Color EnterColor = Color.FromArgb(0, 0, 0); private void txt_kontrIn_Leave(object sender, EventArgs e) { if(txt_kontrIn.Text == "") { txt_kontrIn.Text = (string)txt_kontrIn.Tag; txt_kontrIn.ForeColor = LeaveColor; } } and
private void txt_kontrIn_Enter(object sender, EventArgs e) { if(txt_kontrIn.Text == (string)txt_kontrIn.Tag) { txt_kontrIn.Text = ""; txt_kontrIn.ForeColor = EnterColor; } } How true is this solution and can this code still be shortened?
Ps on the form a lot of textboxes.