public static void AddDefaultTextFromTag(params TextBox[] textBoxes) { foreach (TextBox oTextBox in textBoxes) { bool isPasswordChar = oTextBox.UseSystemPasswordChar; oTextBox.Enter += (sndr, evnt) => { if (((TextBox)sndr).Text == ((TextBox)sndr).Tag.ToString()) { ((TextBox)sndr).Text = ""; ((TextBox)sndr).UseSystemPasswordChar = isPasswordChar; ((TextBox)sndr).ForeColor = SystemColors.WindowText; } }; oTextBox.Leave += (sndr, evnt) => { if (((TextBox)sndr).Text.Trim().Count() == 0) { ((TextBox)sndr).UseSystemPasswordChar = false; ((TextBox)sndr).CharacterCasing = CharacterCasing.Normal; ((TextBox)sndr).Text = ((TextBox)sndr).Tag.ToString(); ((TextBox)sndr).ForeColor = SystemColors.GrayText; } }; if (oTextBox.Text.Trim().Count() == 0) { oTextBox.UseSystemPasswordChar = false; oTextBox.CharacterCasing = CharacterCasing.Normal; oTextBox.Text = oTextBox.Tag.ToString(); oTextBox.ForeColor = SystemColors.GrayText; } } }
TextBox.UseSystemPasswordChar
TextBox.Text
TextBox
Tab
MouseClick
System.Windows.Forms.TextBoxBase.AcceptsTab
MultiLine
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)