I am creating a winforms
application using C#
. Now I want to add a small eye Icon
next to the password textbox
so when the user hovers over the Icon
, one can see what is entered so far. So while hovering, the textbox
should show 123
and when the user leaves the icon the box should be shown as ***
again . Is there any way to do this with C#
?
-
4I don't think the database you're using is relevant. Added the winforms tag. – Dan Guzman Jul 07 '19 at 12:12
-
@DanGuzman *Added the winforms tag* And where is it? – JohnyL Jul 07 '19 at 12:28
-
[TextBox with show password eye icon](https://github.com/r-aghaei/TextBoxWithShowPasswordEyeIcon) – Reza Aghaei Jul 07 '19 at 13:30
3 Answers
textBox.UseSystemPasswordChar = true;
icon.MouseEnter += (sender, e) => textBox.UseSystemPasswordChar = false;
icon.MouseLeave += (sender, e) => textBox.UseSystemPasswordChar = true;

- 3,177
- 6
- 19
- 37
On the hover event use :
Recommended - use an if condition to validate if hover called & set UseSystemPasswordChar
property to true
or false
based on the action.
//hover condition
if() {
textBox1.UseSystemPasswordChar = False;
} else {
textBox1.UseSystemPasswordChar = True;
}
Or
textBox1.PasswordChar = '\0';
The UseSystemPasswordChar property has precedence over the PasswordChar property. Whenever the UseSystemPasswordChar is set to true, the default system password character is used and any character set by PasswordChar is ignored. - Source
More Solutions could be found at here
Official Documentation .Net Framework 4.8:
UseSystemPasswordChar
- This Link
PasswordChar
- This link (Not masked textbox)
MaskedTextBox.PasswordChar
- This link

- 2,040
- 5
- 15
- 35
In hover event on icon, you need change PasswordChar
property of TextBox to char.MinValue
like this:
textBox1.PasswordChar = char.MinValue;
And then if user leave icon, change this property again
textBox1.PasswordChar = '*';

- 907
- 1
- 6
- 13