Can't use button to disable UseSystemPasswordChar

Louis Dolbecq 1 Reputation point
2022-04-11T12:55:40.597+00:00

Hi there,

I got a problem on my project: when i try to to turn false UseSystemPasswordChar, the password does not turn to letter and stay like that • .

I try with every buttons (MaterialSkin and Windows). But if i used radio button, it's functionnal

Does someone know how to solve this ?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,962 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Michael Taylor 54,401 Reputation points
    2022-04-11T13:59:47.78+00:00

    You haven't provided any code or screenshots so it is hard to understand what you mean by using every button and radio button. None of these seem applicable to a TextBox's UseSystemPasswordChar which I'm also assuming you're talking about.

    Assuming you just want to show/hide a password then set UseSystemPasswordChar to true to hide the password and false to show it.

       private void button1_Click ( object sender, EventArgs e )  
       {  
           //Toggle password  
           if (textBox1.UseSystemPasswordChar)  
           {  
               textBox1.UseSystemPasswordChar = false;  
           } else  
               textBox1.UseSystemPasswordChar = true;  
       }  
    

    But if you want to use a custom password char then you need to set PasswordChar instead. If it is NULL (meaning '\0') then no password char is shown.

       private void button1_Click ( object sender, EventArgs e )  
       {  
           //Toggle password  
           if (textBox1.PasswordChar != '\0')  
           {  
               textBox1.PasswordChar = '\0';  
           } else  
               textBox1.PasswordChar = 'x';  
       }  
    

    Note that if you try to combine the two approaches then you need to toggle them both as well but you should really be using one or the other.

    0 comments No comments

  2. Karen Payne MVP 35,426 Reputation points
    2022-04-11T16:14:12.567+00:00

    The following is the same as @Michael Taylor just package differently.

    public static class TextBoxExtensions  
    {  
        public static void ToggleShow(this TextBox sender, bool show = true, char hideWith = '\u25CF')  
        {  
            sender.PasswordChar = show ? '\0' : hideWith;  
        }  
    }  
    

    In a form

    using System;  
    using System.Windows.Forms;  
      
    namespace PassDemo  
    {  
        public partial class Form1 : Form  
        {  
            private const char _hideChar = '\u25CF';  
      
            public Form1()  
            {  
                InitializeComponent();  
                PasswordTextBox.PasswordChar = _hideChar;  
            }  
      
            private void ToggleCheckBox_CheckedChanged(object sender, EventArgs e)  
            {  
                PasswordTextBox.ToggleShow(ToggleCheckBox.Checked, _hideChar);  
            }  
        }  
    }  
    
    
      
    
    0 comments No comments

  3. Louis Dolbecq 1 Reputation point
    2022-04-12T17:57:28.747+00:00

    Hi everyone,

    so my code is the following:

    using MaterialSkin.Controls;  
    using MyPasswordManager.Helper;  
      
    namespace MyPasswordManager  
    {  
        public partial class NewDatabaseForm : MaterialForm  
        {  
            public NewDatabaseForm()  
            {  
                InitializeComponent();  
            }  
            private void TogglePasswords(object sender, EventArgs e)  
            {  
                //Toggle password  
                if (setPassword_TxtBx1.UseSystemPasswordChar)  
                {  
                    setPassword_TxtBx1.UseSystemPasswordChar = false;  
                }  
                else  
                    setPassword_TxtBx1.UseSystemPasswordChar = true;  
            }  
        }  
    }  
    

    The winform looks like this:

    192452-image.png

    I made a gif to show you the problem:

    192471-mypasswordmanager-show-passwords-issue.gif


  4. Louis Dolbecq 1 Reputation point
    2022-04-15T17:36:19.487+00:00

    Hi everyone.

    My problem is solved. Since the next update, MaterialSkin TextBox got a new property named Password. So when i activate it, it's like the UsePasswordChar on Windows TextBox.

    Thank you all for your answers and your help !

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.