For using a masked Password text box in WPF implement below methods:
Class constructor:
public Login_Form()
{
InitializeComponent();
Password_Text_Box.MaxLength = 7; // password 7 characters in length
AutoValidate = AutoValidate.Disable;
} // End of Login form initialization
Component validation:
private void Password_Text_Box_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
bool cancel = false;
if (string.IsNullOrEmpty(Password_Text_Box.Text)) {
cancel = true;
ErrorProvider.SetError(Password_Text_Box, " MISSING PASSWORD "); }
e.Cancel = cancel; }
Logic behind a 'Key Press" action:
private void Password_Text_Box_KeyPress(object sender, KeyPressEventArgs e) {
if (e.KeyChar == (char)Keys.Enter) {
// if ENTER is hit , do something
e.Handled = true; //Handle the Keypress event (suppress the Beep) }
Password_Text_Box.PasswordChar = '*'; // masking input right away
e.Handled = !(char.IsDigit(e.KeyChar) || e.KeyChar == (char)Keys.Back);
e = null;} // not allowing certain types of input
You could also implement a pictogram that reveals and hides the entered sequence:
private void pictureBoxShowPassword_Click(object sender, EventArgs e) {
if (Password_Text_Box.PasswordChar == '*' & Password_Text_Box.Text != null) {
Password_Text_Box.PasswordChar = '\0'; } //revealing
else if (Password_Text_Box.PasswordChar == '\0'){
Password_Text_Box.PasswordChar = '*'; } } // hiding
What happens when you point and click the text box:
private void Password_Text_Box_MouseDown(object sender, MouseEventArgs e) {
if (Password_Text_Box.Text == "Password") {
Password_Text_Box.Text = ""; } }
All in all, you should be looking at something along these lines:
When a form and a text box loads, it displays a text - purpose of the component.
When a user points a mouse and clicks on the component, the purpose text disappears.
Upon entering a value, a masking symbol appears on the screen.
Nearby by the Reveal button lets, you see the entered value before submission.



