How to set a text box for inputing password in winforms?

C#.NetWinforms

C# Problem Overview


how to set a text box for inputing password in winforms? Also I want to show "Capslock is ON" popup if capslock is on.

I want something like

<input type="password" /> in HTML.

C# Solutions


Solution 1 - C#

The best way to solve your problem is to set the UseSystemPasswordChar property to true. Then, the Caps-lock message is shown when the user enters the field and the Caps-Lock is on (at least for Vista and Windows 7).

Another alternative is to set the PasswordChar property to a character value (* for example). This also triggers the automatic Caps-Lock handling.

Solution 2 - C#

To set a text box for password input:

textBox1.PasswordChar = '*';

you can also change this property in design time by editing properties of the text box.

To show if "Capslock is ON":

using System;  
using System.Windows.Forms;  
//...
if (Control.IsKeyLocked(Keys.CapsLock)) {  
    MessageBox.Show("The Caps Lock key is ON.");  
}  

Solution 3 - C#

To make PasswordChar use the ● character instead:

passwordTextBox.PasswordChar = '\u25CF';

Solution 4 - C#

Just set the TextBox.PasswordChar property to '*'.

Solution 5 - C#

Just set the property of textbox that is PasswordChar and set the * as a property of textbox. That will work for password.

  passwordtextbox.PasswordChar = '*';

where passwordtextbox is the text box name.

Solution 6 - C#

private void cbShowHide_CheckedChanged(object sender, EventArgs e)
{
	if (cbShowHide.Checked)
	{
		txtPin.UseSystemPasswordChar = PasswordPropertyTextAttribute.No.Password;
	}
	else
	{
		//Hides Textbox password
		txtPin.UseSystemPasswordChar = PasswordPropertyTextAttribute.Yes.Password;
	}
}

Copy this code to show and hide your textbox using a checkbox

Solution 7 - C#

you can use like these "txtpassword.PasswordChar = '•';"

the use location is ...

 namespace Library_Management_System
    {
        public partial class Login : Form
        {
            public Login()
            {
                InitializeComponent();
                txtpassword.PasswordChar = '•';

Solution 8 - C#

I know the perfect answer:

  1. double click on The password TextBox.

  2. write your textbox name like textbox2.

  3. write PasswordChar = '*';.

  4. I prefer going to windows character map and find a perfect hide like ●.

     example:TextBox2.PasswordChar = '●';
    

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpeckerView Question on Stackoverflow
Solution 1 - C#AxelEckenbergerView Answer on Stackoverflow
Solution 2 - C#z-bossView Answer on Stackoverflow
Solution 3 - C#CharlieView Answer on Stackoverflow
Solution 4 - C#Reed CopseyView Answer on Stackoverflow
Solution 5 - C#NomanJavedView Answer on Stackoverflow
Solution 6 - C#Cwenga ZozoView Answer on Stackoverflow
Solution 7 - C#vinayagamoorthy balalojananView Answer on Stackoverflow
Solution 8 - C#AhmedshaqanbiView Answer on Stackoverflow