Click here to Skip to main content
15,881,455 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
i have a login textbox. Which has propoerty of system password. Which converts plain text into astrick. i.e **** but i want a checkbox on the same windows form to change from system password to normal plain text.
How Can i achieve this?
Posted

C#
void CheckBox1_CheckedChanged(object sender,EventArgs e)
{
 if(CheckBox1.checked=true)
     txtPassword.PasswordChar='0';//The password in the textbox is dispalyed as same characters typed by the user.
 else
     txtPassword.PasswordChar='#';//The password in the textbox is diplayed as a group of '#' characters.
}



PasswordChar isthe cha racter used to mask characters entered in a single-line TextBox control. Set the value of this property to 0 (character value) if you do not want the control to mask characters as they are typed.
 
Share this answer
 
Comments
sariqkhan 20-Nov-12 3:33am    
+5thanks for helping
shaikh-adil 20-Nov-12 4:02am    
+5
C#
private void checkBox_Password_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
                pTextBox.UseSystemPasswordChar = true;
            else
                pTextBox.UseSystemPasswordChar = false;
        }

Hope this help too!
 
Share this answer
 
Comments
sariqkhan 20-Nov-12 8:24am    
thansk for helping sir
:)
C#
void CheckBox_CheckedChanged(object sender, EventArgs e)
{
    TextBox.UseSystemPasswordChar = CheckBox.Checked;
}
 
Share this answer
 
Comments
sariqkhan 20-Nov-12 3:33am    
TextBox.UseSystemPasswordChar for setting to system password
and which property is used for setting it for plan text?
textbox1.??????
Paw Jershauge 20-Nov-12 3:37am    
UseSystemPasswordChar is a bool property. True = **** / False = ABCD

Please try it before replying
sariqkhan 20-Nov-12 3:45am    
yess sir i know that it is bool
i know that sir but according to your answer. i should keep the checkbox checked for using systempassword???
but i want default as system password and if the checkbox is changed means checked then it will be shifted to plain text.
how can i do that?
Paw Jershauge 20-Nov-12 3:49am    
TextBox.UseSystemPasswordChar = true;
CheckBox.Checked = False;
CheckBox.CheckedChanged += new EventHandler(CheckBox_CheckedChanged);
void CheckBox_CheckedChanged(object sender, EventArgs e)
{
TextBox.UseSystemPasswordChar = !CheckBox.Checked;
}
sariqkhan 20-Nov-12 3:56am    
thank you sir,
i can also used if loop for this, your method is also nice
thank you sir for helping me
:)
Use TextMode property[^] of textbox.

C#
YourTextBoxID.TextMode = TextBoxMode.SingleLine; //For normal Plain text

YourTextBoxID.TextMode = TextBoxMode.Password; 


Use the Checkbox's Checked Property[^] to see if the checkBox is checked or not.
 
Share this answer
 
v2
Comments
sariqkhan 20-Nov-12 3:36am    
thanks for helping sir
+5
shaikh-adil 20-Nov-12 4:02am    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900