0

So I have a text box and I have PasswordChar set to true so that when someone clicks the text box it has dots. But what I'm trying to do is make it where it has displaying text on the textbox that says "Password" and when someone clicks the text box the displaying text goes away. http://prntscr.com/je8dnz

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
User101
  • 147
  • 1
  • 2
  • 6
  • Look into the Enter event! – TaW May 05 '18 at 22:39
  • Your image suggests you want to use something that is called `Cue Banner`. Take a look at this answer: https://stackoverflow.com/a/4902969/9365244 – JayV May 05 '18 at 23:03

2 Answers2

2

I am assuming your TextBox's name is textBox1

Anyways, I recommend to look into Events

C# has the very nice Enter event which fulfills exactly what you are asking for.

public Form1()
{
    InitializeComponent();
    textBox1.Enter += TextBox1_Enter;
}

private void TextBox1_Enter(object sender, EventArgs e) 
{
    textBox1.Text = String.Empty;
    textBox1.PasswordChar = '*';
}
0

As you have an OnClick event you can do something similar to the following:

Textbox.Text = "";
Textbox.PasswordChar = '*';

The first line just removed the default text in the box and the second should show any input characters as stars.

Hope it helps.

Shadow
  • 143
  • 8